【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个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- tensorflow学习之路---解决过拟合
''' 思路:1.调用数据集 2.定义用来实现神经元功能的函数(包括解决过拟合) 3.定义输入和输出的数据4.定义隐藏层(函数)和输出层(函数) 5.分析误差和优化数据(改变权重)6.执行神经网络 ' ...
- 【搭建Saltstack运维工具】
目录 所谓Salt 开始搭建 配置接受密钥 salt命令 YAML详解 目标定位字符串 state模块定义主机状态 Salt采集静态信息之GrainsSalt @(Saltstack) *** 所谓S ...
- chgrp---改变文件或目录所属的用户组
chgrp命令用来改变文件或目录所属的用户组.该命令用来改变指定文件所属的用户组.其中,组名可以是用户组的id,也可以是用户组的组名.文件名可以 是由空格分开的要改变属组的文件列表,也可以是由通配符描 ...
- 重新安装python2.6 和 yum (不可以直接安装yum yum 依赖于python2.6)
(升级或卸载Python导致 yum出错) 一: 升级python导致yum出错 1. cd /usr/bin/yum 2. #!/usr/bin/python 修改为 #!/usr/bin ...
- 紫书 例题 9-14 UVa 1218 (树形dp)
这道题有个初始值设成1e9, 然后这个值是要加很多次的,然后就会溢出变成负数, 然后就一直WA, 找这个bug找了一个小时--以后不能随便这样设那么大, 要考虑会不会加很多次然后溢出. 讲一下思路. ...
- xwiki操作手册
Xwiki官网:http://www.xwikichina.com/xwiki/bin/view/Main/中文官网. 1 用户管理 1.1 添加新用户 用户管理需要管理员权限,管理员登陆后 ...
- JBoss配置连接池
什么是数据库连接池? 配置连接池为的是解决效率问题.由于每创建一个连接都是非常耗时的,有了连接池,就能够提前放一些连接进去.以后我们再用连接就去连接池里面取而不是每次都创建.可是我们知道连接池是有上限 ...
- Outlook中设置会议的提醒
https://support.office.com/en-us/article/Set-or-remove-reminders-7a992377-ca93-4ddd-a711-851ef359792 ...
- RTSP、HTTP、HTTPS、SDP四种协议详解
我们将主要讲解RTSP,HTTP,HTTPS, SDP四种协议. 一:RTSP协议简介 实时流协议RTSP是一个应用层协议,用于控制具有实时特性的数据(例如多媒体流)的传送. RTSP协议一般与RT ...
- 网页中插入javascript的几种方法
网页中插入javascript的方法常见的有两种: 一.直接使用html标记 JavaScript 可以出现在 html的任意地方.使用标记<script>…</script> ...