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. C#学习笔记13:静态方法、方法重载和ref、out参数

    静态方法 调用:如果你写的方法和Main()方法在同一个类中,直接写方法名. 如果不在一个类中,需要类名.方法名(); 非静态方法: 调用:创建一个类的对象  对象名.方法名(); Person pe ...

  2. react native for Android (make you first android app)

    第一步:如果你的电脑安装了node,恭喜你,第一步完成:如果没有,那请先安装node. 第二步:安装react-native-cli,在windows下需要从github签下来的react-nativ ...

  3. Fragment的数据传递

    开发之中用到的Fragment的次数越来越多,很多小的项目都已经直接在使用Fragment作为Activity的载体来切换页面.而在开发之中页面的切换我们最关心的问题就是数据的传递了.今天我们主要来研 ...

  4. Android——控制UI界面

    一.使用XML布局文件控制UI界面 res\layout\activity_main.xml代码如下: <FrameLayout xmlns:android="http://schem ...

  5. invalid code signing entitlement的通用暴力解决办法

    1.添加的一台苹果设备为开发机子后,打版本,说profile 没找到,报错 2.上传二进制文件到itunes connect ,报错 3.有时候还什么 appID 无效,报错 烦死他了 我的解决办法, ...

  6. 初尝Windows 下批处理编程

    本文叫“ 初尝Windows 下批处理编程”是为了延续上一篇“初尝 Perl”,其实对于博主而言批处理以及批处理编程早就接触过了. 本文包括以下内容 1.什么是批处理 2.常用批处理命令 3.简介批处 ...

  7. SVN: revert all command

    If you accidentally marked all your files as "delete" (your file/folder has a red x on it) ...

  8. JDBC-ODBC桥接访问SQLServer2008数据库

    来源:十二随风博客 将对JDBC API的调用,转换为对另一组数据库连接API的调用优点:可以访问所有ODBC可以访问的数据库缺点:执行效率低.功能不够强大 (1)建立数据源,注意系统DNS才行,用户 ...

  9. Delphi IDE下载全地址

    Delphi IDE下载全地址: http://pan.baidu.com/share/home?uk=1060104307#category/type=0 还是网友伟大呀.当然有钱的公司还是应该多多 ...

  10. 对WPF中MeasureOverride 和ArrangeOverride 浅理解

    以前对MeasureOverride 和ArrangeOverride十分费解,看到了这篇博文茅塞顿开~ public class CustomControl1 : Panel { /// <s ...