摘要:
There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[...
阅读全文
posted @ 2014-06-19 15:10
OpenSoucre
阅读(272)
推荐(0)
摘要:
Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No...
阅读全文
posted @ 2014-06-18 22:50
OpenSoucre
阅读(143)
推荐(0)
摘要:
Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not...
阅读全文
posted @ 2014-06-18 22:25
OpenSoucre
阅读(131)
推荐(0)
摘要:
Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl...
阅读全文
posted @ 2014-06-18 21:18
OpenSoucre
阅读(171)
推荐(0)
摘要:
Given a singly linked listL: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 exam...
阅读全文
posted @ 2014-06-18 19:45
OpenSoucre
阅读(116)
推荐(0)
摘要:
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu...
阅读全文
posted @ 2014-06-18 17:15
OpenSoucre
阅读(166)
推荐(0)
摘要:
Sort a linked list using insertion sort.单链表的插入排序, 考查的时单链表指针的断开和插入操作#include #include #include using namespace std;struct ListNode{ int val; List...
阅读全文
posted @ 2014-06-18 16:48
OpenSoucre
阅读(123)
推荐(0)
摘要:
Sort a linked list inO(nlogn) time using constant space complexity.本题利用归并排序即可归并排序的核心是将两部分合成一部分,故开始要将链表分成两部分,利用快慢两个指针,当快指针跑到链表尾部时,慢指针恰好在中间,故可以将链表分成两部分然...
阅读全文
posted @ 2014-06-18 16:16
OpenSoucre
阅读(165)
推荐(0)
摘要:
Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.此题是求直线上点最多的点数,根据两点构成一条直线,在同一条直线上,任意两点之间的斜率都相同,故需要对每个点...
阅读全文
posted @ 2014-06-18 14:31
OpenSoucre
阅读(152)
推荐(0)
摘要:
Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express...
阅读全文
posted @ 2014-06-18 12:32
OpenSoucre
阅读(144)
推荐(0)
摘要:
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".此题要注意的几个情况是:(1)输入字符串可能含有前缀0和后缀...
阅读全文
posted @ 2014-06-18 11:17
OpenSoucre
阅读(121)
推荐(0)
摘要:
注意题目给的最后一句话,如果部门任何employee都做不同类型的工作,则这个部门是一个diverse,题目是计算department的diverse数读起来感觉有点别扭,英语没学好的原因 int countGood(vector superior, vector workType) { ...
阅读全文
posted @ 2014-06-16 21:28
OpenSoucre
阅读(209)
推荐(0)
摘要:
一开始Y1,Y2两个参数看不懂,再看一遍题目后才知道,vector索引代表是行数,值代表的是列此题数据量不大,直接深度搜索即可注意这里深度搜索的访问标识不是以前的索引和元素,而是一个交换元素后的整个状态vector,这样可以避免重复元素的搜索 set > visit; bool flag...
阅读全文
posted @ 2014-06-16 20:35
OpenSoucre
阅读(183)
推荐(0)
摘要:
只需要对word遍历一遍即可 int write(string word) { int cnt = 0; for(int i = 0 ; i < word.length(); ++ i){ cnt+=word[i]-'A'+1; ...
阅读全文
posted @ 2014-06-16 20:01
OpenSoucre
阅读(141)
推荐(0)
摘要:
此题给出的条件是:(1)word的每个字母都是大写字母(此条件可以忽略,题目给的输入都是大写字母)(2) 相等字符不能连续,即不能出现AABC的连续相同的情况(3)word中不存在字母组成xyxy的形式,即不存在第一个字符和第3个字符相等同时第2个字符和第4个字符相等的情况对于第(2)种情况,只需要...
阅读全文
posted @ 2014-06-16 20:00
OpenSoucre
阅读(272)
推荐(0)
摘要:
说明自己的8086端口被占用了运行:lsof -i:8086然后kill掉对应的PID
阅读全文
posted @ 2014-06-15 19:39
OpenSoucre
阅读(8)
推荐(0)
摘要:
此题用贪心求解,首先将caramel drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大排序将fruit drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大排序现在有两种可能第一种可能是第一个获得的糖果是caramel drop,则先搜索caramel dro...
阅读全文
posted @ 2014-06-14 23:56
OpenSoucre
阅读(309)
推荐(0)
摘要:
注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移)假设第i行第j列元素aij(注意元素的索引是从0开始的)当aij为D时,此时spiders一直往下移动不可能与Om Nom相遇当aij为U时,此时spiders向上移动时此时Nor...
阅读全文
posted @ 2014-06-14 20:52
OpenSoucre
阅读(300)
推荐(0)
摘要:
暴利搜索即可#include #include #include using namespace std;int main(){ int n,k,x; cin >> n >> k >> x; vector c(n); for(int i = 0 ; i > c[i]; ...
阅读全文
posted @ 2014-06-13 21:05
OpenSoucre
阅读(189)
推荐(0)
摘要:
水到家了#include #include #include using namespace std;struct Point{ int index, pos; Point(int index_ = 0, int pos_ = 0){ index = index_; ...
阅读全文
posted @ 2014-06-13 18:30
OpenSoucre
阅读(152)
推荐(0)
摘要:
模拟即可#include #include #include using namespace std;int main(){ vector a(5); for(int i = 0; i > g[i][j]; } } int maxHappiness = 0; ...
阅读全文
posted @ 2014-06-13 17:53
OpenSoucre
阅读(246)
推荐(0)
摘要:
水题#include #include #include using namespace std;int main(){ vector a(4); cin >> a[0] >> a[1]>>a[2]>>a[3]; string str; cin >> str; int res = 0; for(in...
阅读全文
posted @ 2014-06-13 17:25
OpenSoucre
阅读(154)
推荐(0)
摘要:
看到题目的时候,以为类似插入排序,比较第i个元素和第i-1个元素,如果第i个元素比第i-1个元素小,则不交换如果第i个元素比第i-1个元素大,则交换第i个元素和第i-1个元素 继续比较第i-1个元素与前一个元素,直到前一个元素大为止交换元素次大于等于k则停止但对测试用例1234 3则出现问题,如果...
阅读全文
posted @ 2014-06-13 17:14
OpenSoucre
阅读(196)
推荐(0)
摘要:
从大到小遍历一遍,每次取M个元素,然后求得最小的floor即可 int minimum(int M, vector heights) { sort(heights.begin(),heights.end()); int minFloor = 10000; ...
阅读全文
posted @ 2014-06-13 11:19
OpenSoucre
阅读(184)
推荐(0)
摘要:
排个序,求前k个元素和即可 int minimum(int K, vector danceCost) { sort(danceCost.begin(),danceCost.end()); return accumulate(danceCost.begin()...
阅读全文
posted @ 2014-06-13 11:05
OpenSoucre
阅读(124)
推荐(0)
摘要:
screen 尺寸为a:bvideo 尺寸为 c:d如果a == c 则 面积比为 cd/ab=ad/cb (ad c/d,则ad/bd > cb/db 则(ad > cb) screen尺寸可为 ad:bd, video的尺寸可为 cb:db 面积比为:cb*db/ad*bd = cb/ad...
阅读全文
posted @ 2014-06-12 20:28
OpenSoucre
阅读(166)
推荐(0)
摘要:
水题,注意数据范围即可#include #include #include using namespace std;typedef pair Point;int main(){ int x,y; cin >> x >>y; Point a,b; if((x>0 && y > ...
阅读全文
posted @ 2014-06-12 11:28
OpenSoucre
阅读(137)
推荐(0)
摘要:
1、stl源码2、jsoncpp源码3、Leveldb源码
阅读全文
posted @ 2014-06-11 23:58
OpenSoucre
阅读(161)
推荐(0)
摘要:
第一种方法参考论文《视频跟踪中得背景建模》 在进行孔洞填充时,对像素(x,y)周围的八连通区域进行判断,具体步骤为: (1)首先将原图拷贝到缓存中,然后用以待填充的像素点(x,y)为中心的3x3的块对整幅图像进行扫描,并用计数器记录下这个块所覆盖的9个点中,灰度值为255的点的个数 (2)对计数器N...
阅读全文
posted @ 2014-06-11 22:22
OpenSoucre
阅读(4738)
推荐(0)
摘要:
此题需要注意的两个地方是(1)在某天生产出来的Slimonades,必须在stale_limit天内必须卖完,否则超过stale_limit内抛弃(东西都有保质期)(2)每天生产出来的Slimonades的数量在0到morning[i]之间,而不是morning[i]故第i天卖的东西可能来自max(...
阅读全文
posted @ 2014-06-10 23:23
OpenSoucre
阅读(133)
推荐(0)
摘要:
水题#include #include #include using namespace std;int main(){ int n,m; cin >> n >> m; int cnt = 0, sum = 0; for(int i = 0 ; i > a; i...
阅读全文
posted @ 2014-06-10 12:10
OpenSoucre
阅读(133)
推荐(0)
摘要:
注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C。#include #include #include #include using namespace std;struct Answe...
阅读全文
posted @ 2014-06-10 11:40
OpenSoucre
阅读(173)
推荐(0)
摘要:
注意此题,每一个部分都有一个能量值v[i],他移除第i部分所需的能量是v[f[1]]+v[f[2]]+...+v[f[k]],其中f[1],f[2],...,f[k]是与i直接相连(且还未被移除)的部分的编号。注意题目移除的都是与第i部分直接相连的部分的能量值,将本题目简化得,只考虑两个点1和2,1...
阅读全文
posted @ 2014-06-10 11:31
OpenSoucre
阅读(143)
推荐(0)
摘要:
水题,只要遍历一遍,不够平均数的,从后面的借,比平均数多的,把多余的数添加到后面即可,注意数据范围#include #include #include using namespace std;int main(){ int n; cin >> n; vector a(n); ...
阅读全文
posted @ 2014-06-09 22:36
OpenSoucre
阅读(155)
推荐(0)
摘要:
水题,注意数据范围#include using namespace std;int main(){ long long n,a; cin >> n; long long sum =(n*(n+1))>>1; for(int i = 0 ; i >a; sum ...
阅读全文
posted @ 2014-06-09 22:34
OpenSoucre
阅读(159)
推荐(0)
摘要:
贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完由于数据比较小,可以先打表#include #include #include #include using namespace std;typedef pair Point;int main(){ int n, m, k, f...
阅读全文
posted @ 2014-06-09 21:04
OpenSoucre
阅读(218)
推荐(0)
摘要:
#include #include #include #include using namespace std;int main(){ int n,v; cin >> n >>v; map fruit; for(int i = 0 ; i >a >> b; if...
阅读全文
posted @ 2014-06-09 19:53
OpenSoucre
阅读(210)
推荐(0)
摘要:
水题#include #include #include #include using namespace std;int main(){ int n,v; cin >> n >> v; vector res; for(int i = 0; i > k; for...
阅读全文
posted @ 2014-06-09 19:02
OpenSoucre
阅读(373)
推荐(0)
摘要:
注意p的边界情况,p为0,或者 p为k奇数+偶数 = 奇数奇数+奇数 = 偶数#include #include #include #include #include using namespace std;int main(){ int n,k,p; long a; cin >>...
阅读全文
posted @ 2014-06-09 00:59
OpenSoucre
阅读(216)
推荐(0)
摘要:
注意数据范围即可#include #include #include using namespace std;int main(){ long long n,x; cin >> n >> x; vector c(n); for(int i = 0 ; i > c[i]; ...
阅读全文
posted @ 2014-06-08 22:59
OpenSoucre
阅读(206)
推荐(0)