AtCoder Regular Contest 082 ABCD
A
#include<bits/stdc++.h>
using namespace std;
int a[];
int n,m;
int main(){
cin>>n>>m;
cout<<max(,n-m)<<endl;
return ;
}
B
#include<bits/stdc++.h>
using namespace std;
int a[];
int n,m;
int main(){
string s;
cin>>s;
string ans = "";
for (int i = ; i < s.length(); i += )
{
ans += s[i];
}
cout << ans << endl;
return ;
}
Problem Statement
You are given an integer sequence of length N, a1,a2,…,aN.
For each 1≤i≤N, you have three choices: add 1 to ai, subtract 1 from ai or do nothing.
After these operations, you select an integer X and count the number of i such that ai=X.
Maximize this count by making optimal choices.
Constraints
- 1≤N≤105
- 0≤ai<105(1≤i≤N)
- ai is an integer.
Input
The input is given from Standard Input in the following format:
N
a1 a2 .. aN
Output
Print the maximum possible number of i such that ai=X.
Sample Input 1
7
3 1 4 1 5 9 2
Sample Output 1
4
For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.
Sample Input 2
10
0 1 2 3 4 5 6 7 8 9
Sample Output 2
3
Sample Input 3
1
99999
Sample Output 3
1 解法:数字-1 +1 或者不变,最后留下数字最多的次数
解法:那就...讨论一下
本身的出现次数,i和i+1 i和i+2 i和i+1和i+2的出现次数
#include<bits/stdc++.h>
using namespace std;
long long a[];
int n;
bool vis[];
map<long long,long long>Mp;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
Mp[a[i]]++;
}
long long Max=;
for(int i=;i<=;i++){
Max=max(Max,Mp[i]);
if(Mp[i]&&Mp[i+]&&Mp[i+]){
long long ans=Mp[i]+Mp[i+]+Mp[i+];
Max=max(Max,ans);
}
if(Mp[i]&&Mp[i+]){
long long ans=Mp[i]+Mp[i+];
Max=max(Max,ans);
}
if(Mp[i]&&Mp[i+]){
long long ans=Mp[i]+Mp[i+];
Max=max(Max,ans);
}
}
cout<<Max<<endl;
return ;
}
D - Derangement
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
You are given a permutation p1,p2,…,pN consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero):
Operation: Swap two adjacent elements in the permutation.
You want to have pi≠i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
Constraints
- 2≤N≤105
- p1,p2,..,pN is a permutation of 1,2,..,N.
Input
The input is given from Standard Input in the following format:
N
p1 p2 .. pN
Output
Print the minimum required number of operations
Sample Input 1
5
1 4 3 5 2
Sample Output 1
2
Swap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the condition. This is the minimum possible number, so the answer is 2.
Sample Input 2
2
1 2
Sample Output 2
1
Swapping 1 and 2 satisfies the condition.
Sample Input 3
2
2 1
Sample Output 3
0
The condition is already satisfied initially.
Sample Input 4
9
1 2 4 9 5 8 7 3 6
Sample Output 4
3
题意:交换相邻的数字,使得ai!=i 问最少的次数
解法:贪心,反正如果是正确位置上的,我们去交换相邻的就可以了
#include<bits/stdc++.h>
using namespace std;
int a[];
int n;
bool vis[];
map<int,int>Mp;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]==i){
Mp[i]=;
}
}
int sum=;
for(int i=;i<=n;i++){
if(Mp[i]==){
sum++;
Mp[i]=;
Mp[i+]=;
}
}
cout<<sum<<endl;
return ;
}
AtCoder Regular Contest 082 ABCD的更多相关文章
- AtCoder Regular Contest 082 D Derangement
AtCoder Regular Contest 082 D Derangement 与下标相同与下个交换就好了.... Define a sequence of ’o’ and ’x’ of lengt ...
- AtCoder Regular Contest 082
我都出了F了……结果并没有出E……atcoder让我差4分上橙是啥意思啊…… C - Together 题意:把每个数加1或减1或不变求最大众数. #include<cstdio> #in ...
- AtCoder Regular Contest 082 (ARC082) E - ConvexScore 计算几何 计数
原文链接http://www.cnblogs.com/zhouzhendong/p/8934254.html 题目传送门 - ARC082 E 题意 给定二维平面上的$n$个点,定义全集为那$n$个点 ...
- 【推导】【模拟】AtCoder Regular Contest 082 F - Sandglass
题意:有个沙漏,一开始bulb A在上,bulb B在下,A内有a数量的沙子,每一秒会向下掉落1.然后在K个时间点ri,会将沙漏倒置.然后又有m个询问,每次给a一个赋值ai,然后询问你在ti时刻,bu ...
- 【计算几何】【推导】【补集转化】AtCoder Regular Contest 082 E - ConvexScore
题意:平面上给你N个点.对于一个“凸多边形点集”(凸多边形点集被定义为一个其所有点恰好能形成凸多边形的点集)而言,其对答案的贡献是2^(N个点内在该凸多边形点集形成的凸包内的点数 - 该凸多边形点集的 ...
- 【推导】AtCoder Regular Contest 082 D - Derangement
题意:给你一个排列a,每次可以交换相邻的两个数.让你用最少的交换次数使得a[i] != i. 对于两个相邻的a[i]==i的数,那么一次交换必然可以使得它们的a[i]都不等于i. 对于两个相邻的,其中 ...
- AtCoder Regular Contest 082 E
Problem Statement You are given N points (xi,yi) located on a two-dimensional plane. Consider a subs ...
- AtCoder Regular Contest 082 F
Problem Statement We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contai ...
- 【AtCoder Regular Contest 082 F】Sandglass
[链接]点击打开链接 [题意] 你有一个沙漏. 沙漏里面总共有X单位的沙子. 沙漏分A,B上下两个部分. 沙漏从上半部分漏沙子到下半部分. 每个时间单位漏1单位的沙子. 一开始A部分在上面.然后在r1 ...
随机推荐
- 第三届蓝桥杯决赛c++b组
1.星期几 [结果填空] (满分5分) 1949年的国庆节(10月1日)是星期六. 今年(2012)的国庆节是星期一. 那么,从建国到现在,有几次国庆节正好是星期日呢? 只要 ...
- [原创]Java给word中的table赋值
一.准备工作: 下载PageOffice for Java:http://www.zhuozhengsoft.com/dowm/ 二. 实现方法: 要调用PageOffice操作Word中的tabl ...
- http://www.cnblogs.com/henw/archive/2012/01/06/2314870.html
C#多线程学习 之 线程池[ThreadPool] 在多线程的程序中,经常会出现两种情况: 一种情况: 应用程序中,线程把大部分的时间花费在等待状态,等待某个事件发生,然后才能给予响应 ...
- JavaScript里值比较的方法
JavaScript里值比较的方法 参考资料 一张图彻底搞懂JavaScript的==运算 toString()和valueof()方法的区别 Object.is 和 == 与 === 不同 == 运 ...
- codeforces 651E E. Table Compression(贪心+并查集)
题目链接: E. Table Compression time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- HihoCoder1677 : 翻转字符串(Splay)(区间翻转)
描述 给定一个字符串S,小Hi希望对S进行K次翻转操作. 每次翻转小Hi会指定两个整数Li和Ri,表示要将S[Li..Ri]进行翻转.(S下标从0开始,即S[0]是第一个字母) 例如对于S=" ...
- BZOJ1251 序列终结者(Splay平衡树)(占位)
网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技术含量…… ...
- vim 模式下的几个快捷用法
1.ctrl + v (-- VISUAL BLOCK --) 选中块模式,y 复制,d 剪切,p 粘贴,Esc退出模式 2.Shift + v (-- VISUAL LINE -- ) 快速行选 ...
- css3渐变gradient
参考: http://www.w3cplus.com/content/css3-gradient
- BZOJ3219:巡游
浅谈树分治:https://www.cnblogs.com/AKMer/p/10014803.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem. ...