• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






canexjtuzju

记录
 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

随笔分类 -  Codility

 
Colidity-- MaxDoubleSliceSum
摘要:左右两次遍历,记录以当前元素结尾的左边最大字串和以及右边最大字串和,最后遍历,相加 1 // you can also use includes, for example: 2 // #include 3 #include 4 #include 5 int solution(vector &A... 阅读全文
posted @ 2014-09-18 10:46 canexjtuzju 阅读(229) 评论(0) 推荐(0)
Colidity-- EquiLeader
摘要:由于要满足equi-leader,则必须是整个数组的leader,证明如下:leader > i+1/2 && leader > (n-i-1)/2,那么leader > n/2我之前c++写了,但是有错五 1 static int equiLeader(int[] a){ 2 int len ... 阅读全文
posted @ 2014-09-17 16:29 canexjtuzju 阅读(320) 评论(0) 推荐(0)
Colidity-- Dominator
摘要:统计cnt,等于零则更换当前元素但是注意:最后得到的索引要再遍历一边数组统计是否超过一半 1 int solution(vector &A) { 2 // write your code in C++11 3 int cnt = 0; 4 int cur = -1; 5 ... 阅读全文
posted @ 2014-09-17 16:07 canexjtuzju 阅读(229) 评论(0) 推荐(0)
Colidity-- Fish
摘要:1 #include 2 // you can write to stdout for debugging purposes, e.g. 3 // cout &A, vector &B) { 6 // write your code in C++11 7 stack s; 8 ... 阅读全文
posted @ 2014-09-17 15:57 canexjtuzju 阅读(169) 评论(0) 推荐(0)
Colidity-- StoneWall
摘要:最简单的思路就是:每次选最小的,算一块;然后对最小值左右两边递归的解子问题加上备忘录应该能够转化为DP但是我没有尝试这里参考了一个贪心的算法 1 // you can use includes, for example: 2 // #include 3 #include 4 // you can... 阅读全文
posted @ 2014-09-17 10:34 canexjtuzju 阅读(334) 评论(0) 推荐(0)
Colidity-- NumberOfDiscIntersections
摘要:先对区间左边界排序,在对右边界左二分查找 1 // you can use includes, for example: 2 #include 3 4 // you can write to stdout for debugging purposes, e.g. 5 // cout other... 阅读全文
posted @ 2014-09-16 15:32 canexjtuzju 阅读(388) 评论(1) 推荐(0)
Colidity--Triangle
摘要:判断数组中是否存在满足形成三角形的条件的三个数。判断连续相邻的三个数即可;可以证明当步相邻的时候存在的的话,那么就一定会有一组相邻的是满足的。 1 // you can use includes, for example: 2 #include 3 4 // you can write to s... 阅读全文
posted @ 2014-09-16 10:20 canexjtuzju 阅读(184) 评论(0) 推荐(0)
Colidity--CountDiv
摘要:很巧妙的思路:先计算A之前的被K除的最大数,然后计算B-A之间能填充多少个K 1 // you can use includes, for example: 2 // #include 3 4 // you can write to stdout for debugging purposes, ... 阅读全文
posted @ 2014-09-15 22:23 canexjtuzju 阅读(153) 评论(0) 推荐(0)
Colidity--MinAvgTwoSlice
摘要:这题挺有意思的,没想到规模大于3的slice的avg肯定要比它的子slice(小于3)的avg来得小的话,就不太好写。 1 int solution(vector &A) { 2 // write your code in C++98 3 int minStart = 0; 4 ... 阅读全文
posted @ 2014-09-15 22:07 canexjtuzju 阅读(217) 评论(0) 推荐(0)
Colidity--GenomicRangeQuery
摘要:思路:统计每一个字符前面的四个字符的个数(利用前缀和数组),这样就能在O(1)时间得到某个区间某个字符的个数开始想到的是O(n^2)的空间,这个思路比较好 1 // you can use includes, for example: 2 // #include 3 4 // you can w... 阅读全文
posted @ 2014-09-15 21:58 canexjtuzju 阅读(426) 评论(0) 推荐(0)
Colidity--PassingCars
摘要:1 // you can use includes, for example: 2 // #include 3 4 // you can write to stdout for debugging purposes, e.g. 5 // cout &A) { 8 // write y... 阅读全文
posted @ 2014-09-15 21:20 canexjtuzju 阅读(401) 评论(0) 推荐(0)