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的更多相关文章

  1. Codility NumberSolitaire Solution

    1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...

  2. codility flags solution

    How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...

  3. GenomicRangeQuery /codility/ preFix sums

    首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...

  4. H - The Falling Leaves

    Description Each year, fall in the North Central region is accompanied by the brilliant colors of th ...

  5. *[codility]Peaks

    https://codility.com/demo/take-sample-test/peaks http://blog.csdn.net/caopengcs/article/details/1749 ...

  6. *[codility]Country network

    https://codility.com/programmers/challenges/fluorum2014 http://www.51nod.com/onlineJudge/questionCod ...

  7. *[codility]AscendingPaths

    https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...

  8. *[codility]MaxDoubleSliceSum

    https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...

  9. *[codility]Fish

    https://codility.com/demo/take-sample-test/fish 一开始习惯性使用单调栈,后来发现一个普通栈就可以了. #include <stack> us ...

  10. *[codility]CartesianSequence

    https://codility.com/programmers/challenges/upsilon2012 求笛卡尔树的高度,可以用单调栈来做. 维持一个单调递减的栈,每次进栈的时候记录下它之后有 ...

随机推荐

  1. Android调用系统相机以及自定义相机

    0.综述 自定义相机,此处展示简单的相机功能,官方文档中还有相应关于视频拍摄的内容,此处不提 1.添加权限 <!--相机权限,数据存储--> <uses-permission and ...

  2. Spring 3.x 实践 第一个例子(Spring 3.x 企业应用开发实战读书笔记第二章)

    前言:工作之后一直在搞android,现在需要更多和后台的人员交涉,技术栈不一样,难免鸡同鸭讲,所以稍稍学习下. 这个例子取自于<Spring 3.x 企业应用开发实战>一书中的第二章,I ...

  3. 12天学好C语言——记录我的C语言学习之路(Day 11)

    12天学好C语言--记录我的C语言学习之路 Day 11: 因为指针部分比较的难,所以我们花费的时间也是最长的,希望大家耐的住性子,多多理解,多多打代码.好了,废话不多说,来看第11天的学习. //编 ...

  4. 04斐波那契函数_Fibonacci--(栈与队列)

    #include "stdio.h" int Fbi(int i) /* 斐波那契的递归函数 */ { ) ? : ; ) + Fbi(i - ); /* 这里Fbi就是函数自己, ...

  5. (转)解读Flash矩阵

    转自: http://hi.baidu.com/cabtw/item/d2dbd212d4ae3e9398ce337f 图片看不到请去原网站看 Matrix: scale(a,d); 比例变换就是将平 ...

  6. JavaScript对象应用-字符串和图片对象

    1.1 应用 String对象截取特定文字   利用String 对象的charAt() 和 substring() 方法等,截取特定文字或字段文字显示在页面上 <html> <he ...

  7. C++ 二维数组(双重指针作为函数参数)

    本文的学习内容参考:http://blog.csdn.net/yunyun1886358/article/details/5659851 http://blog.csdn.net/xudongdong ...

  8. linux命令行下命令参数前的一横(-)和两横(--)的区别

    原文转自:http://blog.csdn.net/songjinshi/article/details/6816776 在解释这些区别之前我们先了解一下有关linux的背景知识,这个需要大家先认真看 ...

  9. 高并发编程陷阱之check and set

    今天公司CTO跟隔壁部门开技术会,旁听了一下.所讲的内容感觉好高大上啊!简单记录一下 场景是这样的: if(check(id)===true) { }else{ set(id); } 什么意思呢? 就 ...

  10. Yii 验证码验证

    控制器如下