Codeforces 900C. Remove Extra One(暴力)
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible.
We remind that in a sequence of numbers a1, a2, ..., ak the element ai is a record if for every integer j (1 ≤ j < i) the following holds: aj < ai.
The first line contains the only integer n (1 ≤ n ≤ 105) — the length of the permutation.
The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation. All the integers are distinct.
Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one.
1
1
1
5
5 1 2 3 4
5
In the first example the only element can be removed.
题意:
如果一个数比前面的数都大,那么就产生一个贡献
现在要你去掉一个数,使得剩下数字串总贡献最大,求这个数
如果几个数字一样,输出较大的
题解:
这题似乎可以用树状数组手糊,但标算更加高妙
因为最大值可以删去,所以我们关心的不仅只有最大值,还有次大的
一组数字,没有修改的话原本的贡献是相同的,所以问题就变成了去掉一个数最多能增加多少贡献
这该怎么记录呢?
如果有一个数比当前最大数大,那么去掉它会产生负贡献
如果比最大值大,比次大值小,那么去掉最大值会增加一个贡献
所以建一个cnt数组,cnt[i]表示去掉其所增加的贡献
扫一遍取最大值即可
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; int n,a[],cnt[]; int main()
{
int max1=,max2=;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++)
{
if(a[i]>max1)
{
max2=max1;
max1=a[i];
cnt[a[i]]--;
}
else
{
if(a[i]>max2)
{
cnt[max1]++;
max2=a[i];
}
}
}
int ans,max3=-;
for(int i=;i<=n;i++)
{
if(cnt[i]>max3)
{
max3=cnt[i];
ans=i;
}
}
printf("%d\n",ans);
}
Codeforces 900C. Remove Extra One(暴力)的更多相关文章
- Codeforces 900C Remove Extra One 模拟
题目链接:900C Remove Extra One 题意: 首先record是指这个数比数列前面的所有数都大,给了n个数(1-n),删掉一个数,让整个数列的record值达到最大. 题解: 刚开始我 ...
- Codeforces Round #450 (Div. 2) C. Remove Extra One【*模拟链表/一个数比前面所有数大就是个record。删掉一个数,让record的个数尽量多。】
C. Remove Extra One time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- [CodeForces - 1272D] Remove One Element 【线性dp】
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...
- Codeforces Round #450 (Div. 2) C. Remove Extra One
题目链接 题意:让你去掉一个数,使得剩下的数的record最多,当1≤j<i的aj<ai1 \leq j< i的a_j<a_i1≤j<i的aj<ai时aia_i ...
- 【Codeforces Round #450 (Div. 2) C】Remove Extra One
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举删除第i个数字. 想想删掉这个数字后会有什么影响? 首先,如果a[i]如果是a[1..i]中最大的数字 那么record会减少1 ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- [ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力
Couple Cover Time Limit: 3000MS Memory Limit: 524288KB 64bit IO Format: %I64d & %I64u Descri ...
随机推荐
- ASP.NET WebApi通过自定义ControllerSelector来自定义Controller的选择
在web api中,我们可以通过给Cotroller类添加RoutePrefixAttribute来定义url与Controller之间的映射,但是有时候有一些特殊情况下,我们需要做一些特殊处理来将某 ...
- datasnap的初步
datasnap的初步-回调函数 服务器端 TServerMethods1 =class(TComponent) private { Private declarations } public { P ...
- C# byte数组转成Bitmap对象
方法一: /// <summary> /// 将数组转换成彩色图片 /// </summary> /// <param name="rawValues" ...
- 蓝桥杯 算法训练 ALGO-36 传纸条
算法训练 传纸条 时间限制:1.0s 内存限制:512.0MB 问题描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而 ...
- Oracle10g客户端连接远程数据库配置图解
yuanwen:http://blog.csdn.net/DKZhu/article/details/6027933 一. 安装oracle客户端 1. 运行setup.exe,出现 2. ...
- Unity3D版本之我见
关心Unity版本的变化以及了解未来版本的内容是专业做Unity的同学必备的功课,下面我来说一下我对4.0以后版本的一些见解. v4.0: 这个版本比3.5有较大的跳跃,首先最大卖点是新的动作系统Me ...
- Proxmark3笔记(一)
Kali下使用Proxmark3 apt-get update apt-get install build-essential libreadline5 libreadline-dev libusb- ...
- VMWARE 虚拟机新增硬盘,格式化分区,并挂载
VMWARE 虚拟机新增 硬盘 并挂载 一台虚拟机上安装ORACLE12c 需要分一块硬盘挂载数据文件 日志文件 以及归档文件 1. 关闭虚拟机 2. 编辑虚拟机设置 选择[编辑虚拟机设置]并打开,将 ...
- python的ftplib模块
Python中的ftplib模块 Python中默认安装的ftplib模块定义了FTP类,其中函数有限,可用来实现简单的ftp客户端,用于上传或下载文件 FTP的工作流程及基本操作可参考协议RFC95 ...
- 用Python+Django在Eclipse环境下开发web网站
一.创建一个项目如果这是你第一次使用Django,那么你必须进行一些初始设置.也就是通过自动生成代码来建立一个Django项目--一个Django项目的设置集,包含了数据库配置.Django详细选项设 ...