Codeforces 900C Remove Extra One 模拟
题意:
首先record是指这个数比数列前面的所有数都大,给了n个数(1-n),删掉一个数,让整个数列的record值达到最大。
题解:
刚开始我的思路是求这个数列中前面比这个数大的有几个(因为只有前面只有一个数大于这个数的数可以增加record值)求出后找比求出个数为1的数大的最近数。后来发现这中方法代码量实在太大了,而且在求出后再求最近的大于这个数的数的复杂度也好像不够。
后来看了题解,发现只要换一种思路就很简单,那就是求删除某个位置上的数可以增加多少的record。只用设置两个数(最大值和次大值),在遍历时有数掉在这两个之间就让vec[max1]++(次小值改变);如果小于次小值这个数就肯定无法成为record值,如果大于最大值那么就改变最大值和次大值(注意这种情况,设置最大值的时候要在最大值-1,因为最大值被取掉后一定少了一个record)。
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5+;
int vec[MAX_N];
int main()
{
int N;
while(cin>>N)
{
memset(vec,,sizeof(vec));
int mx = , mx2 = ;
for(int i=;i<N;i++)
{
int x ;
scanf("%d",&x);
if(x > mx)
{
mx2 = mx;
mx = x;
vec[mx] --;
}
else if(x > mx2)
{
vec[mx] ++;
mx2 = x;
}
}
int maxn = -;
int ans = ; // ans = 1可以省去N=1时的特判
for(int i=;i<=N;i++)
{
if(vec[i] > maxn)
{
maxn = vec[i];
ans = i;
}
}
cout<<ans<<endl;
}
}
Codeforces 900C Remove Extra One 模拟的更多相关文章
- Codeforces 900C. Remove Extra One(暴力)
You are given a permutation p of length n. Remove one element from permutation to make the number of ...
- 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.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- [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 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
随机推荐
- linux保持管道中颜色显示
在linux工作中,不同类型的文件以不同的颜色显示,如文件夹显示蓝色,压缩文件显示橘黄色,可执行文件显示为绿色,链接失效文件高亮显示等等: 有时候根据颜色可以快速鉴别,如我有时为了保持目录的完整性,会 ...
- Gradle、Gradle Wrapper与Android Plugin for Gradle
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- 关于SPF记录的说明
详细了解SPF记录的可以查看一下这篇博文:http://www.renfei.org/blog/introduction-to-spf.html 关于 SPF SPF:Sender Policy Fr ...
- css实现梯形标签页
html <nav>click me</nav> css nav{ position: relative; display: inline-block; padding: 15 ...
- mysql之数据操作
一 介绍 MySQL数据操作: DML 在MySQL管理软件中,可以通过SQL语句中的DML语言来实现数据的操作,包括 使用INSERT实现数据的插入 UPDATE实现数据的更新 使用DELETE实现 ...
- 【Tarjan缩点】POJ2186 Popular Cows
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 35644 Accepted: 14532 De ...
- linux之 NFS服务器与客户端的安装与配置
今天实验室需要搭建NAS,我负责的是NFS的安装与配置,现将整理的文档分享一下: 参考一:Linux下rpm 安装包方式安装 http://linux.chinaunix.net/techdoc/be ...
- Python pandas ERROR 2006 (HY000): MySQL server has gone away
之前在做python pandas大数据分析的时候,在将分析后的数据存入mysql的时候报ERROR 2006 (HY000): MySQL server has gone away 原因分析:在对百 ...
- LeetCode第[16]题(Java):3Sum Closest 标签:Array
题目难度:Medium 题目: Given an array S of n integers, find three integers in S such that the sum is closes ...
- myeclipse 扩展内存大小
工具中修改设置Default VM ArgumentsWindows-> Preferences->Java->Installed JREs,点击右侧的jdk,然后点击"E ...