【Codeforces Round #450 (Div. 2) C】Remove Extra One
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
枚举删除第i个数字。
想想删掉这个数字后会有什么影响?
首先,如果a[i]如果是a[1..i]中最大的数字
那么record会减少1.
其次。
对于任意一个a[j],且i则我们可以预处理一下。
遍历a
对于a[i]
看看它是不是a[1..i]中第二小的数字。
那么标记cnt[a[1..i]中最大的数字]++;
然后再重新遍历一遍a;
对于a[i]
还是看它是不是a[1..i]中第二小的数字。
如果是的话,标记cnt[a[1..i]中最大的数字]--;
同时temp = cnt[a[i]] - (a[i]==max{a[1..i]}?1:0);
这里的temp就是去掉数字a[i]后,record的变化量.
取temp最大的a[i]就好
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
map<int,int> dic;
int n,a[N+10],ma[N+10],ma2[N+10];
int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i];
ma[1] = a[1];
ma2[1] = -1;
for (int i = 2;i <= n;i++){
if (a[i]>ma[i-1]){
ma2[i] = ma[i-1];
ma[i] = a[i];
}else{
ma[i] = ma[i-1];
if (ma2[i-1]<a[i]){
ma2[i] = a[i];
}else ma2[i] = ma2[i-1];
}
if (a[i]!=ma[i] && a[i]==ma2[i]){
dic[ma[i]]++;
}
}
int tot = -1e6,idx = -1;
for (int i = 1;i <= n;i++){
if (a[i]!=ma[i] && a[i]==ma2[i]) dic[ma[i]]--;
int temp = dic[a[i]];
if (a[i]==ma[i]) temp--;
if (temp>tot){
tot = temp;
idx = a[i];
}else if (temp==tot){
idx = min(idx,a[i]);
}
}
cout << idx << endl;
return 0;
}
【Codeforces Round #450 (Div. 2) C】Remove Extra One的更多相关文章
- 【Codeforces Round #450 (Div. 2) A】Find Extra One
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟. 看看Y左边或右边的点个数是否<=1 [代码] #include <bits/stdc++.h> using ...
- 【Codeforces Round #450 (Div. 2) B】Position in Fraction
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找循环节就好. ->其实可以不用找出来整个循环节. 有找到c就直接输出. 找到了循环节还没找到的话,直接输出无解. [代码] ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- linux 查看tomcat 实时日志
进入tomcat下logs文件夹下,若没有Catalina.out文件先去启动服务在回到logs文件夹输入 tail -f catalina.out ,可看到实时日志
- eclipse 安装javaEE插件 和html\xml\jsp编辑器
1 在Eclipse中菜单help选项中选择install new software选项 2 在work with 栏中输入 http://download.eclipse.org/releases/ ...
- 【Henu ACM Round#18 B】Modulo Sum
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] m比较小 <=1000 a[i]直接看成a[i]%m就可以了. 有n个0..999之间的整数.. 如果有一个0那么就直接输出Y ...
- 【Eclipse中使用Git之一】把远程仓库的项目,clone到eclipse里面
[Eclipse中使用Git之一]把远程仓库的项目,clone到eclipse里面 2015-01-29 19:25 15779人阅读 评论(1) 收藏 举报 .embody{ padding:10p ...
- Maintaining processor resources during architectural events
In one embodiment of the present invention, a method includes switching between a first address spac ...
- ZOJ 2562 HDU 4228 反素数
反素数: 对于不论什么正整数x,起约数的个数记做g(x).比如g(1)=1,g(6)=4. 假设某个正整数x满足:对于随意i(0<i<x),都有g(i)<g(x),则称x为反素数. ...
- 从Java到C++——常量的使用规则
常量是一种标识符,它的值在执行期间恒定不变.C语言用 #define来定义常量(称为宏常量). C++ 语言除了 #define外还能够用const来定义常量(称为const常量). 一.为什么须要常 ...
- js实现 导航移入移出效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 如何监控和解决SQL Server的阻塞(1) (当前阻塞)
1. 什么是"阻塞"? 阻塞是SQL数据库应用"锁"机制的一个副作用.当一个应用请求针对某个数据库对象(例如全表,某行数据, 或者是某个数据页)加锁后,那么这个 ...
- require和import的使用
一.前言 ES6标准发布后,module成为标准,标准的使用是以export指令导出接口,以import引入模块,但是在我们一贯的node模块中,我们采用的是CommonJS规范,使用require引 ...