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 ...
随机推荐
- 修改ubuntu14.04命令行启动
方法1: 原来要想默认不进入xwindows,只需编辑文件”/etc/default/grub”, 把 GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” 改成GRUB ...
- UTCformat 转换UTC时间并格式化成本地时间
/** * UTCformat 转换UTC时间并格式化成本地时间 * @param {string} utc */ UTCformat (utc) { var date = new Date(utc) ...
- the art of seo(chapter eleven)
Tracking Results and Measuring Success goal -> driver ***Why Measuring Success Is Essential to th ...
- tensorflow knn 预测房价 注意有 Min-Max Scaling
示例数据: 0.00632 18.00 2.310 0 0.5380 6.5750 65.20 4.0900 1 296.0 15.30 396.90 4.98 24.00 0.02731 0.00 ...
- POJ3693Maximum repetition substring (循环节)(后缀数组+RMQ)
The repetition number of a string is defined as the maximum number R such that the string can be par ...
- 数据结构与算法(4)----->链表、二分搜索
1. 链表的基本概念 链表和数组一样都是一种线性结构; 数组是一段连续的存储空间; 链表空间不一定保证连续,是临时分配的; 链表的分类 按方向: 单链表:每个节点只能通过next指针指向下一个节点; ...
- 使用webdriver出现的问题:[18796:1808:0730/131103.313:ERROR:install_util.cc(600)] Failed to read HKLM\SOFTWARE\Policies\Google\Chrome\MachineLevelUserCloudPolicyEnrollmentToken: 系统找不到指定的文件。 (0x2) DevTools lis
1.注册表导致 [5956:4996:0710/155156.898:ERROR:install_util.cc(589)] Unable to create registry key HKLM\SO ...
- Dubbo配置设计
配置分类 配置格式 配置加载 可编程配置 配置缺省值 配置一致性 配置覆盖 配置继承 配置向后兼容 配置分类 首先,配置的用途是有多种的,大致可以分为: 环境配置,比如:连接数,超时等配置. 描述配置 ...
- 洛谷 1131 [ZJOI2007]时态同步——树形dp
题目:https://www.luogu.org/problemnew/show/P1131 因为越高,调节一个影响到的越多,所以底下只要把子树间的差异消除了就行了,与其他部分的差异由更高的边调节. ...
- poj2127——LCIS
题目:http://poj.org/problem?id=2127 LCIS,注意存储路径的方法. 代码如下: #include<iostream> #include<cstdio& ...