您的位置:首页 > 其它

Codeforces - 862A Mahmoud and Ehab and the MEX

2017-09-20 11:35 411 查看
[align=center]A. Mahmoud and Ehab and the MEX[/align]
[align=center][/align]
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.

Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integersevil if the
MEX of it is exactly
x. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, theMEX of the set
{0, 2, 4} is1 and the
MEX of the set{1, 2, 3} is
0 .

Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations
Dr. Evil has to perform to make his set evil?

Input
The first line contains two integers n andx (1 ≤ n ≤ 100,0 ≤ x ≤ 100) — the size of the set Dr. Evil
owns, and the desiredMEX.

The second line contains n distinct non-negative integers not exceeding100 that represent the set.

Output
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.

Examples

Input
5 3
0 4 5 6 7


Output
2


Input
1 0
0


Output
1


Input
5 0
1 2 3 4 5


Output
0


Note
For the first test case Dr. Evil should add 1 and2 to the set performing
2 operations.

For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so theMEX of it is
0.

In the third test case the set is already evil.

题意:给你一个集合和一个邪恶数字M,问你最少要多少个操作,才能使得M是这个集合里最小的非负整数。操作包括,删除数字和添加数字。

解题思路:由于集合很小,直接暴力计算即可。详细看代码注释。其实就是看看集合里有多少个比M小的数。然后简单算算就可以了。

#include<iostream>
#include<deque>
#include<memory.h>
#include<stdio.h>
#include<map>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long int ll;

int a[200];

int main(){

int n,m;
cin>>n>>m;

for(int i=0;i<n;i++)
cin>>a[i];

sort(a,a+n);//可忽略……

int i;
int num=0;

//计算集合里比M小的数有多少个,直接枚举每一个数看看集合里有没有
for(i=0;i<m;i++){
for(int j=0;j<n;j++){
if(a[j]==i){
num++;
}
}
}

//看看有没有跟M大小一个的数,有的话需要一个删除操作。这里aaa要么0要么1.
int aaa=0;
for(int j=0;j<n;j++){
if(a[j]==m){
aaa++;
}
}

//答案
cout<<m-num+aaa<<endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: