[codility]Falling-discs
http://codility.com/demo/take-sample-test/omega2013
这题有点意思。首先经过思考,想到从底部往上扫,去迎接掉下来的disc。但这样仍然是不行的。后来看了答案,需要转化一下。因为从上往下看时,井里面下面大的圆都被上面小的圆遮住了,所以可以削去。
int solution(vector<int> &A, vector<int> &B) {
// write your code in C++98
for (int i = 0; i < A.size(); i++) {
if (i > 0 && A[i] > A[i-1]) {
A[i] = A[i-1];
}
}
int count = 0;
int i = 0;
int j = A.size() - 1;
while (i < B.size() && j >= 0) { // i
while (j >= 0 && B[i] > A[j]) {
j--;
}
if (j >= 0) {
j--;
count++;
}
i++;
}
return count;
}
[codility]Falling-discs的更多相关文章
- Codility NumberSolitaire Solution
1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...
- codility flags solution
How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...
- GenomicRangeQuery /codility/ preFix sums
首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...
- H - The Falling Leaves
Description Each year, fall in the North Central region is accompanied by the brilliant colors of th ...
- *[codility]Peaks
https://codility.com/demo/take-sample-test/peaks http://blog.csdn.net/caopengcs/article/details/1749 ...
- *[codility]Country network
https://codility.com/programmers/challenges/fluorum2014 http://www.51nod.com/onlineJudge/questionCod ...
- *[codility]AscendingPaths
https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...
- *[codility]MaxDoubleSliceSum
https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...
- *[codility]Fish
https://codility.com/demo/take-sample-test/fish 一开始习惯性使用单调栈,后来发现一个普通栈就可以了. #include <stack> us ...
- *[codility]CartesianSequence
https://codility.com/programmers/challenges/upsilon2012 求笛卡尔树的高度,可以用单调栈来做. 维持一个单调递减的栈,每次进栈的时候记录下它之后有 ...
随机推荐
- android手机震动
Vibrator是安卓提供的震动器,其没有构造器,通过getSystemService(Context.VIBRATOR_SERVICE)方法获取对象.但使用此类时需要在清单文件中添加访问权限andr ...
- (一)问候Spring4
第一节:Spring 简介 Spring 作者:Rod Johnson: 官方网站:http://spring.io/ 最新开发包及文档下载地址:http://repo.springsource.or ...
- 检测PC端和移动端的方法总结
正在苦逼的实习中,昨天公司让做一个页面,涉及到检测终端的问题,如果是手机设备,就跳转到指定的网页上,以前写响应式布局只要用@media screen来实现布局的差异化适应,但是现在不仅仅是布局,还要针 ...
- 关于Ionic的安装
Ionic是一个前端的框架,帮助开发者使用HTML5, CSS3和JavaScript做出原生应用. http://ionicframework.com/getting-started/ 这里介绍了如 ...
- [PR & ML 3] [Introduction] Probability Theory
虽然学过Machine Learning和Probability今天看着一part的时候还是感觉挺有趣,听惊呆的,尤其是Bayesian Approach.奇怪发中文的笔记就很多人看,英文就没有了,其 ...
- BYTE、WORD与DWORD类型
Original Link: http://hi.baidu.com/vnxuaqndtncrxyr/item/f67c83872cf80cd65e0ec10d Author: 厚积薄发 在Visu ...
- How do I create an installation log?
Quote from: http://www.advancedinstaller.com/user-guide/qa-log.html Windows Installer logging Window ...
- java中instanceof和getClass()的作用
初学者难免有点混淆java中instanceof和getClass()的作用, 下面就来一一讲解. 父类A: class A { } 子类B: class B extends A { } 构造对象 ...
- jQuery1.8以上,ajaxSend,ajaxStart等一系列事件要绑定在document上才有效果
jQuery1.8以上,ajaxSend,ajaxStart等一系列事件要绑定在document上才有效果
- C# 读取快捷方式指向的文件
C# 读取快捷方式指向的文件 [Flags()] public enum SLR_FLAGS { SLR_NO_UI = 0x1, SLR_ANY_MATCH = 0x2, SLR_UPDATE = ...