http://codility.com/demo/take-sample-test/maxcounters

简单题。注意要记录两个max,一个是最大值,一个是已经生效的最大值。

// you can also use includes, for example:
// #include <algorithm>
vector<int> solution(int N, vector<int> &A) {
// write your code in C++98
int max_val = 0;
int effective_max = 0;
vector<int> ans(N);
for (int i = 0; i < A.size(); i++) {
if (A[i] <= N) {
int idx = A[i] - 1;
if (ans[idx] < effective_max)
ans[idx] = effective_max;
ans[idx]++;
if (ans[idx] > max_val) {
max_val = ans[idx];
}
}
else {
effective_max = max_val;
}
}
for (int i = 0; i < N; i++) {
if (ans[i] < effective_max)
ans[i] = effective_max;
}
return ans;
}

  

*[codility]MaxCounters的更多相关文章

  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. *[codility]Peaks

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

  5. *[codility]Country network

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

  6. *[codility]AscendingPaths

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

  7. *[codility]MaxDoubleSliceSum

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

  8. *[codility]Fish

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

  9. *[codility]CartesianSequence

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

随机推荐

  1. Android进阶——声波振幅显示

    最近博主想做一个app,中间有一个是录音的功能.于是博主想把UI做的好看一些,想仿照微信或者QQ语音输入时,能够随着声音的大小显示声波振幅.于是查找了一些资料,现在把这个功能的Demo分享给大家,以后 ...

  2. java反射案例讲解

    本篇文章依旧采用小例子来说明,因为我始终觉的,案例驱动是最好的,要不然只看理论的话,看了也不懂,不过建议大家在看完文章之后,在回过头去看看理论,会有更好的理解. 下面开始正文. [案例1]通过一个对象 ...

  3. content = "IE=edge,chrome=1" 详解

    content = "IE=edge,chrome=1" 详解 < meta http-equiv = "X-UA-Compatible" content ...

  4. Sophos UTM WebAdmin存在未明漏洞

                                                                                                        ...

  5. Spring切面处理

    切面类DictionaryAOP 里面有一个全局变量systemTestDomain <bean id="dictionaryAOP" class="test.Di ...

  6. ios数据库FMDB

    一.下载fmdb类库 二.添加libsqulite3.0.dylib 三.添加头文件#import "FMDB.h" 四.打开数据库 a.设置路径NSString *path = ...

  7. javascript 事件 第23节

    <html> <head> <title>DOM对象</title> <style type="text/css"> t ...

  8. ubuntu 恢复gnome-panel

    Ubuntu重启panel 的方法首先进入终端, 依次输入以下命令1.gconftool --recursive-unset /apps/panel2.rm -rf ~/.gconf/apps/pan ...

  9. [PR & ML 4] [Introduction] Model Selection & The Curse of Dimension

    这两部分内容比较少,都是直觉上的例子和非正式的定义,当然这本书中绝大多数定义都是非正式的,但方便理解.后面深入之后会对这两个章节有详细的阐述.

  10. 国内IT技术博客对比

    今天我想就自己对用了国内几个IT行业领先的博客做一个心得体会的总结: 我总共是用了三个,第一个是新浪,第二个是CSDN,第三个是博客园: 当然期间有自己搭建过wordpress,也用了一段时间,但是感 ...