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 ...
随机推荐
- jsp参数传递
jsp参数传递 jsp中四种传递参数的方法 1.form表单 2.request.setAttribute();和request.getAttribute(); 3.超链接:<a herf=&q ...
- oracle数据库-备份ORACLE为dmp类型数据
刘备,为自己后期脑子不灵光时可以找个可以翻阅的地方. 一.第一部分导出ORACLE数据 1.数据库地址及账号密码: 数据库地址:10.10.10.132账号密码:oracle/oracle 2.使用X ...
- github添加ssh公钥
使用git作为版本维护工具非常方便,而且一般个人用github作为远端库就够用了.而一般git连接github的方式采用ssh的方法,http的会略微慢一些.所以为了方便一般会在github设置中添加 ...
- Android Studio 主题、字体大小的设置
1. Android Studio 主题的设置: 设置Android Studio 自带的主题 设置第三方主题 2. Android Studio 字体的设置 设置左面包名的字体大小 设置右面代码编辑 ...
- Python: scikit-image 彩色图像滤波
一般的滤波器都是针对灰度图像的,scikit-image 库提供了针对彩色图像滤波的decorator:adapt_rgb,adapt_rgb 提供两种形式的滤波,一种是对rgb三个通道分别进行处理, ...
- Unity-2017.2官方实例教程Roll-a-ball(二)
声明: 本文系转载,由于Unity版本不同,文中有一些小的改动,原文地址:http://www.jianshu.com/p/97b630a23234 上一节Unity-2017.2官方实例教程Roll ...
- ACM学习历程—POJ1151 Atlantis(扫描线 && 线段树)
Description There are several ancient Greek texts that contain descriptions of the fabled island Atl ...
- BZOJ3674:可持久化并查集加强版
浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...
- Spring管理Filter和Servlet(在servlet中注入spring容器中的bean)
在使用spring容器的web应用中,业务对象间的依赖关系都可以用context.xml文件来配置,并且由spring容器来负责依赖对象 的创建.如果要在servlet中使用spring容器管理业务对 ...
- Behave + Selenium(Python) 四
来自T先生 今天我们开始讲讲behave的厉害的地方. Tag文件的使用 在behave里面,如何来控制哪些case需要run,哪些case不需要run,这个时候就用Tag来控制.好了,接下来我用Ta ...