*[codility]MaxCounters
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的更多相关文章
- 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 ...
- *[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之Http网络编程(二)
上一篇文章简单的介绍了Android中http的两种通信方式,并且分别用获取百度网页做了实例.但是在实际应用中,更多的是客户端通过请求的参数来实现在服务端的具体操作,并最终返回数据给客户端.因为我们不 ...
- Javascript原型钩沉
写在前面的总结: JS当中创建一个对象有好几种方式,大体上就是以下几种: ①通过var obj ={...} 这种方式一般称为字面量方式,{}直接写需要定义的字段 ②var obj = new Obj ...
- someExperience
// 面试题1 var name = 'World'; (function () { if (typeof name==='undefined') { var name = 'jack'; conso ...
- java集合 collection-list-vector
import java.util.*; /* 枚举就是Vector特有的取出方式. 发现枚举和迭代器很像. 其实枚举和迭代是一样的. 因为枚举的名称以及方法的名称都过长. 所以被迭代器取代了. 枚举郁 ...
- 2017 google Round C APAC Test 题解
题解参考网上的答案,以及我自己的想法. 主要参考网站:http://codeforces.com/blog/entry/47181,http://codeforces.com/blog/entry/4 ...
- jQuery—一些常见方法(3)【width(),innerWidth(),outerWidth()】
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Python3 面向对象
Class 在Python中,定义类是通过class关键字: class Student(object): pass class后面紧接着是类名,即Student,类名通常是大写开头的单词,紧接着是( ...
- struts2 修改action的后缀
struts2 修改action的后缀 struts2 的默认后缀是 .action 虽然很直观,但是很烦琐.很多人喜欢将请求的后缀改为 .do 在struts2中修改action后缀有两种比较简单的 ...
- VB-获取某字符在其中出现的次数
'方法1: Dim str As String " "))) '方法2: Dim n&, j& j = n = , text1.Text, "/ITEMN ...
- Java学习--封装、继承、多态
接下来几天会根据http://www.cnblogs.com/chenssy/category/525010.html中讲解的java内容做个学习笔记,在此感谢一下这位大仙!! 一.封装 对于封装而言 ...