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 ...
随机推荐
- python 数据库查询结果转对象
#coding:utf-8 from json import dumps, loads, JSONEncoder, JSONDecoder import pickle from app.model.J ...
- resharper activate
K03CHKJCFT-eyJsaWNlbnNlSWQiOiJLMDNDSEtKQ0ZUIiwibGljZW5zZWVOYW1lIjoibnNzIDEwMDEiLCJhc3NpZ25lZU5hbWUiO ...
- MAC 10.6 64wei
苹果电脑 Mac OS X 10.6 雪豹系统同时支持 32 位和 64 位模式,关于开启 64 位的好处,字太多,本文后半段介绍.下面先说查看你的苹果电脑是否开启了 64 位以及设置苹果电脑 Mac ...
- 解决:An internal error occurred during: "Launching New_configuration". Path for project must have only one segment.
问题: 点击运行时eclipse报错如下: An internal error occurred during: "Launching New_configuration". Pa ...
- mac下自定义伪协议配置
之前查了很多资料,最近也在挖掘研究这方面的漏洞. windows的很简单,在注册表配置就好了,但是mac os 是unix的,没有注册表这么一说. 但是发现腾讯等配置了自定义等协议,例如:tencen ...
- Sublime Text 套件介紹:Pretty JSON
JSON,一個輕量級的資料交換語言,目前許多網站AJAX request的回應結果都是JSON格式 以下是一個標準的JSON格式 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...
- peerconnection_client分析笔记
Windows版本的peerconnection_client demo是一个win32程序,入口函数为main.cc里面的wWinMain,程序整体流程就从这个入口函数下手开始分析. 1.peer ...
- Unity3d平台信息设置
[Unity3d平台信息设置] 通过"Edit" -> "Project Settings" -> "Player"菜单选项.打 ...
- as+bt=1是ab两数互质的充要条件
[as+bt=1是ab两数互质的充要条件] 充分性,as+bt=1 => (a,b)=1: 因为as+bt=1,设c=(a,b),则c整除a和b,所以c整除as+bt,即c整除1,所以c=1,即 ...
- Linux VmWare安装虚拟机(centos6.9)
开启虚拟机 ---------------------------------------------------------------------------------------------- ...