Codeforces 900C-Remove Extra One
来源:互联网 发布:网络简介阅读答案 编辑:程序博客网 时间:2024/05/22 03:11
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.
11
1
55 1 2 3 4
5
In the first example the only element can be removed.
题意:给一个N个数的排列,要求移走一个数,使得record数最多。record数就是这个数比排在它前面的数都大
解题思路:如果a[i]如果是a[1..i]中最大的数字那么record会减少1。对于任意一个a[j],且i<j且a[i]是a[1..j]中最大的数字,且a[j]是a[1..j]中第二大的数字,删掉a[i]后,a[j]都会成为一个record,即record数递增
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>#include <ctime>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;int n, a[100009], cnt[100009];int main(){while (~scanf("%d", &n)){for (int i = 1; i <= n; i++) scanf("%d", &a[i]);memset(cnt, 0, sizeof cnt);int mx1 = 0, mx2 = 0;for (int i = 1; i <= n; i++){if (a[i] > mx1){mx2 = mx1;mx1 = a[i];cnt[a[i]]--;}else if (a[i] > mx2){cnt[mx1]++;mx2 = a[i];}}int ans, mx = -10;for (int i = 1; i <= n; i++)if (cnt[i] > mx) mx = cnt[i], ans = i;printf("%d\n", ans);}return 0;}
- codeforces 900C. Remove Extra One
- Codeforces 900C-Remove Extra One
- Codeforces 900C Remove Extra One
- codeforces 900C. Remove Extra One
- 【Codeforces 900C】Remove Extra One(BIT思维)
- Codeforces Round #450 (Div. 2) C. Remove Extra One 暴力
- codeforces Remove Extra One(思维)
- CF#450 C.Remove Extra One
- codeforces 900A. Find Extra One
- CF 900.C Remove Extra One 单调栈+BIT
- Remove Extra One Codeforces Round #450 (Div. 2)(线段树)
- 900AFind Extra One
- CF900C:Remove Extra One(思维)
- A. Find Extra One
- CodeForces 135C C. Zero-One
- C - Extra Krunch
- careercup1.3: remove duplicate without extra space.
- C++: Compile error: extra qualification
- 自动提取OULP-C1V2_Pack步态数据库,并合成步态能量图
- Day05_jaxp修,删,改,遍历
- JavaScript闭包
- [Linux] Linux/Mac OS history命令 添加时间,用户,ip
- 【论文笔记】CycleGAN
- Codeforces 900C-Remove Extra One
- CF 294C. Shaass and Lights 组合数学
- Attribute-Enhanced Face Recognition with Neural Tensor Fusion Networks 阅读笔记
- Tianhe2使用
- Python sklearn包中的一些小函数笔记
- C语言assert宏的使用
- Ubuntu16.04+CUDA9+cudnn7+python3.5+源码编译Tensorflow1.4+opencv3.3
- Mysqlserver安装错误
- C++多继承