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. CSS3实现水位充满文字特效

    CSS3实现水位充满文字特效是一款既是Loading特效也是文字特效,Loading动画开始时,文字中的水位渐渐上升,为了模拟水位上升的真实效果,水面还会波浪浮动,当Loading动画结束时,文字中的 ...

  2. TP框架控制器和对应方法创建

    控制器和对应方法创建 控制器是MVC模式中的核心,TP默认有一个控制器:   Index控制器里面有一个操作方法:Index   我们在访问http://localhost:8080/Thinkphp ...

  3. Smarty模板重点汇总

    Smarty模板重点回顾:1.功能:前后端分离:2.实现方法:通过使用Smarty的核心类来实现,利用display方法来读取模板文 件,用正则进行替换,替换完保存到临时文件,再将临时文件加载到当前页 ...

  4. Java中内部类中使用外面变量为什么final修饰?

    所以final从语法上约束了实际上两个不同变量的一致性(表现为同一变量). 我的理解: 例如这样的代码: public void test(String str){ str="abc&quo ...

  5. 详解linux上定时函数 setitimer

    setitimer()为Linux的API,并非C语言的Standard Library,setitimer()有两个功能, 一是指定一段时间后,才执行某个function,二是每间格一段时间就执行某 ...

  6. Scala学习——操作符(初)

    经常看到却反应不出来的(->) val a = 2 val b = a->4 //表示生成一个tuple println(b._1+" "b._2) //2 4

  7. mina2中的线程池

    一.Mina中的线程池模型 前面介绍了Mina总体的层次结构,那么在Mina里面是怎么使用Java NIO和进行线程调度的呢?这是提高IO处理性能的关键所在.Mina的线程调度原理主要如下图所示: A ...

  8. android TextView selector点击样式改变

    1.selector 从单词的意思来说:选择器,就是对你的目标的控制.selector主要是用在ListView的item单击样式和TextView和Button的点击样式. 2.主要属性介绍: an ...

  9. 【245】◀▶IEW-Unit10

    Unit 10 Censorship 1. Model1题目及范文分析 Some parents believe that there is no harm in allowing their chi ...

  10. Http协议-报文

    2013的双12即将到来,网上购物是大家所熟悉的.看中小米电视时,可以先下订单然后再付款,电商根据订单将小米电视正确安全的送达给我们.包裹包含电视的基本信息及电视的使用说明书,使我们能够初步的了解它的 ...