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 Na1,a2,…,aN.

For each 1≤iN, 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≤iN)
  • 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

Copy
7
3 1 4 1 5 9 2

Sample Output 1

Copy
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

Copy
10
0 1 2 3 4 5 6 7 8 9

Sample Output 2

Copy
3

Sample Input 3

Copy
1
99999

Sample Output 3

Copy
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 pii for all 1≤iN. 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

Copy
5
1 4 3 5 2

Sample Output 1

Copy
2

Swap 1 and 4, then swap 1 and 3p 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

Copy
2
1 2

Sample Output 2

Copy
1

Swapping 1 and 2 satisfies the condition.


Sample Input 3

Copy
2
2 1

Sample Output 3

Copy
0

The condition is already satisfied initially.


Sample Input 4

Copy
9
1 2 4 9 5 8 7 3 6

Sample Output 4

Copy
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的更多相关文章

  1. AtCoder Regular Contest 082 D Derangement

    AtCoder Regular Contest 082 D Derangement 与下标相同与下个交换就好了.... Define a sequence of ’o’ and ’x’ of lengt ...

  2. AtCoder Regular Contest 082

    我都出了F了……结果并没有出E……atcoder让我差4分上橙是啥意思啊…… C - Together 题意:把每个数加1或减1或不变求最大众数. #include<cstdio> #in ...

  3. AtCoder Regular Contest 082 (ARC082) E - ConvexScore 计算几何 计数

    原文链接http://www.cnblogs.com/zhouzhendong/p/8934254.html 题目传送门 - ARC082 E 题意 给定二维平面上的$n$个点,定义全集为那$n$个点 ...

  4. 【推导】【模拟】AtCoder Regular Contest 082 F - Sandglass

    题意:有个沙漏,一开始bulb A在上,bulb B在下,A内有a数量的沙子,每一秒会向下掉落1.然后在K个时间点ri,会将沙漏倒置.然后又有m个询问,每次给a一个赋值ai,然后询问你在ti时刻,bu ...

  5. 【计算几何】【推导】【补集转化】AtCoder Regular Contest 082 E - ConvexScore

    题意:平面上给你N个点.对于一个“凸多边形点集”(凸多边形点集被定义为一个其所有点恰好能形成凸多边形的点集)而言,其对答案的贡献是2^(N个点内在该凸多边形点集形成的凸包内的点数 - 该凸多边形点集的 ...

  6. 【推导】AtCoder Regular Contest 082 D - Derangement

    题意:给你一个排列a,每次可以交换相邻的两个数.让你用最少的交换次数使得a[i] != i. 对于两个相邻的a[i]==i的数,那么一次交换必然可以使得它们的a[i]都不等于i. 对于两个相邻的,其中 ...

  7. AtCoder Regular Contest 082 E

    Problem Statement You are given N points (xi,yi) located on a two-dimensional plane. Consider a subs ...

  8. AtCoder Regular Contest 082 F

    Problem Statement We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contai ...

  9. 【AtCoder Regular Contest 082 F】Sandglass

    [链接]点击打开链接 [题意] 你有一个沙漏. 沙漏里面总共有X单位的沙子. 沙漏分A,B上下两个部分. 沙漏从上半部分漏沙子到下半部分. 每个时间单位漏1单位的沙子. 一开始A部分在上面.然后在r1 ...

随机推荐

  1. redis持久化的方式RDB 和 AOF

    redis持久化的方式RDB 和 AOF 一.对Redis持久化的探讨与理解 目前Redis持久化的方式有两种: RDB 和 AOF 首先,我们应该明确持久化的数据有什么用,答案是用于重启后的数据恢复 ...

  2. String类中的equals是如何重写的

    我们知道String中的equals方法是被重写过的,因为object的equals方法是比较的对象的内存地址,而String的equals方法比较的是对象的值. 首先几个知识点: 基本数据类型==比 ...

  3. django model中get()和filter()方法的区别

    django的get()方法是从数据库的取得一个匹配的结果,返回一个对象,如果记录不存在的话,它会报错. django的filter()方法是从数据库的取得匹配的结果,返回一个对象列表,如果记录不存在 ...

  4. THUPC2019划水记

    虽然早就打不动了,虽然一个队友提前说好跑路了,还是两个人来玩了玩.最大的失误是没有开场打模拟题,然后就没骗到钱,还是要向某一心骗钱不顾排名的队伍学习.这次的模拟题超简单,很愉快地就打完了,也没调多久, ...

  5. tcpdump抓包工具用法说明

    tcpdump采用命令行方式对接口的数据包进行筛选抓取,其丰富特性表现在灵活的表达式上. 不带任何选项的tcpdump,默认会抓取第一个网络接口,且只有将tcpdump进程终止才会停止抓包. 例如: ...

  6. BZOJ3110:[ZJOI2013]K大数查询

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...

  7. BZOJ3123:[SDOI2013]森林

    浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...

  8. C#中如何获取其他进程的命令行参数 ( How to get other processes's command line argument )

    Subject: C#中如何获取其他进程的命令行参数 ( How to get other processes&apos;s command line argument )From: jian ...

  9. python+ mysql存储二进制流的方式

    很多时候我们为了管理方便会把依稀很小的图片存入数据库,有人可能会想这样会不会对数据库造成很大的压力,其实大家可以不用担心,因为我说过了,是存储一些很小的图片,几K的,没有问题的! 再者,在这里我们是想 ...

  10. Day06:迭代器,生成器,生成表达式,面向过程编程,包及常用模块

    今日内容:1.迭代器(****)2.生成器(***)3.生成器表达式(*****)4.面向过程编程(*****)5.包的使用(***)6.常用模块    logging (*****)    re ( ...