自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(47)
  • 收藏
  • 关注

原创 libevent2源码 min_heap

位于 minheap-internal.h , 是一个堆的实现主要代码有

2014-11-21 21:22:37 374

原创 Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [

2014-11-16 21:38:07 272

原创 Minimum Path Sum

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at

2014-11-16 19:53:21 281

原创 Maximum Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha

2014-11-15 20:55:58 323

原创 Decode Ways

A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total numb

2014-11-15 20:39:04 295

原创 Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),

2014-11-13 23:49:32 310

原创 Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?DP最简单的题目

2014-11-13 23:03:38 299

原创 Linked List Cycle

Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?经典的快慢指针class Solution {public: bool hasCycle(ListNode *head) { Li

2014-10-30 21:55:52 274

原创 Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?

2014-10-30 21:22:33 240

原创 Reorder List

Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to 

2014-10-30 17:15:58 246

原创 Binary Tree Preorder Traversal

Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti

2014-10-30 13:46:39 290

原创 Binary Tree Postorder Traversal

Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut

2014-10-30 13:45:45 298

原创 LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if

2014-10-30 10:28:27 408

原创 Insertion Sort List

Sort a linked list using insertion sort.单链表插入排序,没啥好说的class Solution {public: ListNode * pickMin(ListNode * & head){ ListNode * mins = head, *cur = head; while(cur){

2014-10-29 23:29:55 227

原创 Sort List

Sort a linked list in O(n log n) time using constant space complexity.单链表排序,要求O(n

2014-10-29 23:18:34 315

原创 Max Points on a Line

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.找一个二维图

2014-10-22 16:09:54 330

原创 Evaluate Reverse Polish Notation

计算逆波兰

2014-10-22 14:35:04 312

原创 Reverse Words in a String

Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes

2014-10-22 12:50:16 368

原创 Maximum Product Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest pr

2014-10-22 11:21:11 344

原创 Find Minimum in Rotated Sorted Array

Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in

2014-10-16 21:45:13 283

原创 1002. A+B for Polynomials

1002. A+B for Polynomials (25)时间限制 400 ms内存限制 32000 kB代码长度限制 16000 B判题程序 Standard 作者 CHEN, YueThis time, you are supposed to find A+B where A and B

2014-07-29 00:50:22 394

原创 1001. A+B Format (20)

Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).InputEach input file contains

2014-04-29 20:06:11 440

原创 Basic Level 1025. 反转链表 (25)

给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转。输入格式: 每个输入包含1个测试用例。每个测试用例第1行给出第1个结点的地址、结点总个数正整数N(5)、以及正整数K(接下来有N行,每行格式为:Address Da

2014-03-24 00:30:35 442

原创 Basic Level 1024. 科学计数法 (20)

科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+-][0-9]+,即数字的整数部分只有1位,小数部分至少有1位,该数字及其指数部分的正负号即使对正数也必定明确给出。现以科学计数法的格式给出实数A,请编写程序按普通数字表示法输出A,并保证所有有效位都被保留。输入格式: 每个输入包含1个测试用例,即一个以科学计数法表示的

2014-03-23 23:39:58 429

原创 Basic Level 1023. 组个最小数 (20)

给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意0不能做首位)。例如:给定两个0,两个1,三个5,一个8,我们得到的最小的数就是10015558。现给定数字,请编写程序输出能够组成的最小的数。输入格式: 每个输入包含1个测试用例。每个测试用例在一行中给出10个非负整数,顺序表示我们拥有数字0、数字1、……数字9的个数。整数间用一

2014-03-23 22:57:49 618

原创 Basic Level 1022. D进制的A+B (20)

输入两个非负10进制整数A和B(30-1),输出A+B的D (1 输入格式: 输入在一行中依次给出3个整数A、B和D。 输出格式: 输出A+B的D进制数。 输入样例:123 456 8输出样例:1103#include #include #include #include #include using namespace std;int

2014-03-23 22:48:23 411

原创 Basic Level 1021. 个位数统计 (15)

给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0ik-1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定N = 100311,则有2个0,3个1,和1个3。输入格式: 每个输入包含1个测试用例,即一个不超过1000位的正整数N。输出格式: 对N中每一种不同的个位数字,以D:M的格式在一行中输出该位数字D及其在N中出现的次数M。

2014-03-23 22:27:54 533

原创 Basic Level 1020. 月饼 (25)

月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有3种月饼,其库存量分别为18、15、10万吨,总售价分别为75、72、45亿元。如果市场的最大需求量只有20万吨,那么我们最大收益策略应该是卖出全部15万吨第2种

2014-03-23 22:23:21 524

原创 Basic Level 1019. 数字黑洞 (20)

给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字。一直重复这样做,我们很快会停在有“数字黑洞”之称的6174,这个神奇的数字也叫Kaprekar常数。例如,我们从6767开始,将得到7766 - 6677 = 10899810 - 0189 = 96219621 - 1269 = 8352

2014-03-23 21:42:32 416

原创 Basic Level 1018. 锤子剪刀布 (20)

大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。 输入格式: 输入第1行给出正整数N(5),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。输出格式:

2014-03-23 20:57:02 630

原创 Basic Level 1017. A除以B (20)

本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数。你需要输出商数Q和余数R,使得A = B * Q + R成立。输入格式: 输入在1行中依次给出A和B,中间以1空格分隔。 输出格式: 在1行中依次输出Q和R,中间以1空格分隔。 输入样例:123456789050987654321 7输出样例:17636684150141093474 3

2014-03-23 17:00:21 385

原创 Basic Level 1016. 部分A+B (15)

正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA。例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6。现给定A、DA、B、DB,请编写程序计算PA + PB。输入格式: 输入在一行中依次给出A、DA、B、DB,中间以空格分隔,其中0 10。输出格式: 在一行中输出PA + PB的值。 输入样例1:3862

2014-03-23 16:56:36 509

原创 Basic Level 1015. 德才论 (25)

宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”现给出一批考生的德才分数,请根据司马光的理论给出录取排名。 输入格式: 输入第1行给出3个正整数,分别为:N(5),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才

2014-03-23 16:47:39 469

原创 Basic Level 1014. 福尔摩斯的约会 (20)

大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母'D',代表星期四;第2对相同的字符是'E',那是第5个英文字母,代表一天里的第14个钟头

2014-03-23 15:52:43 351

原创 Basic Level 1013. 数素数 (20)

令Pi表示第i个素数。现任给两个正整数M 4,请输出PM到PN的所有素数。输入格式: 输入在一行中给出M和N,其间以空格分隔。输出格式: 输出从PM到PN的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。输入样例:5 27输出样例:11 13 17 19 23 29 31 37 41 4347 53 59 61 67 71 73 79 83

2014-03-20 20:12:03 510

原创 Basic Level 1012. 数字分类 (20)

给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字:A1 = 能被5整除的数字中所有偶数的和; A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...; A3 = 被5除后余2的数字的个数; A4 = 被5除后余3的数字的平均数,精确到小数点后1位; A5 = 被5除后余4的数字中最大数字。输入格式: 每个输入包含1个测试用例。每个测试用例先

2014-03-20 18:35:05 385

原创 Basic Level 1011. A+B和C (15)

给定区间[-231, 231]内的3个整数A、B和C,请判断A+B是否大于C。 输入格式: 输入第1行给出正整数T(输出格式: 对每组测试用例,在一行中输出“Case #X: true”如果A+B>C,否则输出“Case #X: false”,其中X是测试用例的编号(从1开始)。输入样例:41 2 32 3 42147483647 0 21474836460 -21

2014-03-20 17:57:13 600

原创 Basic Level 1010. 一元多项式求导 (25)

设计函数求一元多项式的导数。输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。输入样例:3 4 -5 2 6 1 -2 0输出样例:12 3 -10 1 6 0注意事项就是如果最后没有指数>0的项了,至少输

2014-03-20 17:52:43 619

原创 Basic Level 1009. 说反话 (20)

给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。输出格式:每个测试用例的输出占一行,输出倒序后的句子。输入样例:Hello World Here I Come

2014-03-20 17:27:56 400

原创 Basic Level 1008. 数组元素循环右移问题 (20)

一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1……AN-1)变换为(AN-M …… AN-1 A0 A1……AN-M-1)(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?输入格式:每个输入包含一个测试用例,第1行输入N ( 1=0);第2行输入N个整数,

2014-03-20 17:24:10 400

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除