摘要:
http://codility.com/demo/take-sample-test/treeheight非常非常简单的求树的深度。不忍直视。// you can also use includes, for example:// #include int get_height(tree * T) { if (T->l == NULL && T->r == NULL) return 0; int hl = 0; int hr = 0; if (T->l != NULL) hl = get_height(T->l); if (T->r !=... 阅读全文
posted @ 2013-11-14 23:02
阿牧遥
阅读(316)
评论(0)
推荐(0)
摘要:
http://codility.com/demo/take-sample-test/equileader一开始想到从左和右两边开始扫取众数,但求众数又要重新扫一遍,这样复杂度就是O(n^2)了。此题的关键在于Equi-Leader必然是众数,否则不可能左边和右边都是众数。所以先求出众数及其出现次数,再扫就行了。// you can also use includes, for example:// #include int solution(vector &A) { // write your code in C++98 int x = A[0]; int cnt = 0; ... 阅读全文
posted @ 2013-11-14 22:51
阿牧遥
阅读(689)
评论(0)
推荐(0)
摘要:
https://codility.com/demo/take-sample-test/stone_wall拼石块。用最少的方块。一开始想了想用贪心,是可行的,就是尽量每次把当前的高度往右延伸到最多,比如7,8,7,那么7往右延伸可以覆盖到第二个7,这样减掉,后面的就变成1,0了,问题仍然等价。但这样... 阅读全文
posted @ 2013-11-14 21:26
阿牧遥
阅读(699)
评论(0)
推荐(0)
摘要:
http://codility.com/demo/take-sample-test/beta2010/这题以前做的时候是先排序再二分,现在觉得没有必要。首先圆可以看成线段,把线段的进入作为一个事件,出去作为一个事件。注意根据题意,同样的点,进入要在出去之前。那么O(n)扫一遍就可以得到结果。注意的是... 阅读全文
posted @ 2013-11-14 19:31
阿牧遥
阅读(376)
评论(0)
推荐(0)
摘要:
http://codility.com/demo/take-sample-test/genomicrangequery这题有点意思。一开始以为是RMQ或者线段树,但这样要O(n*logn)。考虑到只有四种字符,可以用数组记录每个字符i之前出现过几次。二,查询区间是闭区间,所以要处理off by on... 阅读全文
posted @ 2013-11-14 15:40
阿牧遥
阅读(542)
评论(0)
推荐(0)
摘要:
http://codility.com/demo/take-sample-test/maxcounters简单题。注意要记录两个max,一个是最大值,一个是已经生效的最大值。// you can also use includes, for example:// #include vector so... 阅读全文
posted @ 2013-11-14 14:59
阿牧遥
阅读(532)
评论(0)
推荐(0)
摘要:
http://codility.com/demo/take-sample-test/tapeequilibrium简单题。记录到i为止的sum就可以了。O(n)。// you can also use includes, for example:// #include int solution(vector &A) { // write your code in C++98 int total = 0; vector sum; for (int i = 0; i tmp) ans = tmp; } return ans;} 阅读全文
posted @ 2013-11-14 14:41
阿牧遥
阅读(324)
评论(0)
推荐(0)

浙公网安备 33010602011771号