【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

枚举删除第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的更多相关文章

  1. 【Codeforces Round #450 (Div. 2) A】Find Extra One

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟. 看看Y左边或右边的点个数是否<=1 [代码] #include <bits/stdc++.h> using ...

  2. 【Codeforces Round #450 (Div. 2) B】Position in Fraction

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找循环节就好. ->其实可以不用找出来整个循环节. 有找到c就直接输出. 找到了循环节还没找到的话,直接输出无解. [代码] ...

  3. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  4. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  5. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  6. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  7. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  8. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

  9. 【Codeforces Round #423 (Div. 2) A】Restaurant Tables

    [Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...

随机推荐

  1. XFCE 桌面环境美化,fedora27系统

    一.添加RPM Fusion源,安装方法这里就不说了以前的文章里写过. 二.安装XFCE 主题管理器 xfce-theme-manager [root@Fedora ~]# dnf install x ...

  2. BZOJ1189: [HNOI2007]紧急疏散evacuate(二分答案,最大流)

    Description 发生了火警,所有人员需要紧急疏散!假设每个房间是一个N M的矩形区域.每个格子如果是'.',那么表示这是一 块空地:如果是'X',那么表示这是一面墙,如果是'D',那么表示这是 ...

  3. 安卓https

    http://www.tuicool.com/articles/NrmE3e http://blog.csdn.net/guestcode/article/details/50194357 http: ...

  4. 自考之SDT

    软件开发工具(Soft Development Tools)是一本让程序猿了解自己自己所使用工具的书,作为一个刚刚接触编程的小菜鸟.计划工具.分析工具.设计工具.尽管用的都不是非常多,但也有一个概念了 ...

  5. 在OEL 5.4 32bit上使用yum install命令遇到的问题

    在OEL 5.4 32bit上使用yum install命令遇到的问题 [root@localhost yum.repos.d]# yum install elfutils-libelf-devel- ...

  6. 对string的一些扩展函数

    对string作了一些扩展,包含string转化为int.string转化为double.string转化为bool.打印系统当前时间.但没有解决数据溢出的问题,请大神帮忙解决! //头文件 /*pa ...

  7. IOS 以随意点为圆心 旋转UIView

    环绕底边中点旋转                     UIView本身是支持旋转的,能够用UIView.transform属性实现旋转. The origin of the transform i ...

  8. OJ刷题---猜算式

    题目要求: 输入代码: #include<iostream> using namespace std; void Calc(); int main() { Calc(); return 0 ...

  9. JavaFX 一 出生新手村(阅读小规则)

    我就不讲IDE怎么装的,网上有的是,我仅仅是说说我学习过程中遇到的,该注意的东西 1.JavaFX刚開始出是基于脚本script开发的语言,所以网上会有流传比較多关于script的JavaFX,对于被 ...

  10. Onvif开发之客户端鉴权获取参数篇

    前面一篇已经介绍了客户端如何发些设备,下面这篇简单介绍下在发现设备后,如何通过ONVIF协议来获取设备的相关参数 ONVIF中不管是客户端还是设备端,最先实现的接口都是关于能力的那个接口,在客户端实现 ...