Codeforces --- Mahmoud and Ehab and the MEX
2017-11-25 01:10
441 查看
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 integers evil 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, the MEX of the set {0, 2, 4} is 1 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 and x (1 ≤ n ≤ 100, 0 ≤ x ≤ 100) — the size of the set Dr.
Evil owns, and the desired MEX.
The second line contains n distinct non-negative integers not exceeding 100 that represent the set.
Output
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
Example
Input
Output
Input
Output
Input
Output
输入n,x
n代表 a【i】的长度。
s输出经过 多少次操作可是使得最小未出现非负整数是x
每次操作可以拿走一个数字或者添加一个数字
小于等于x 的所有的数字我们都给标记
并且我们要知道x 的出现次数 ///也就是我们要拿走的操作
如果前边没有出现的数字我们要增加上。
operator = 添加 + 拿走的X
#include<bits/stdc++.h>
using namespace std;
int vis[10005];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(vis,0,sizeof(vis));
for(int i=0; i<n; i++)
{
int x;
scanf("%d",&x);
if(x<=m&&x>=0)
{
vis[x]++;
}
}
int res=0;
for(int i=0; i<m; i++)
{
if(vis[i]==0)res++;
}
res+=vis[m];
printf("%d\n",res);
}
}
Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil 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, the MEX of the set {0, 2, 4} is 1 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 and x (1 ≤ n ≤ 100, 0 ≤ x ≤ 100) — the size of the set Dr.
Evil owns, and the desired MEX.
The second line contains n distinct non-negative integers not exceeding 100 that represent the set.
Output
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
Example
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
输入n,x
n代表 a【i】的长度。
s输出经过 多少次操作可是使得最小未出现非负整数是x
每次操作可以拿走一个数字或者添加一个数字
小于等于x 的所有的数字我们都给标记
并且我们要知道x 的出现次数 ///也就是我们要拿走的操作
如果前边没有出现的数字我们要增加上。
operator = 添加 + 拿走的X
#include<bits/stdc++.h>
using namespace std;
int vis[10005];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(vis,0,sizeof(vis));
for(int i=0; i<n; i++)
{
int x;
scanf("%d",&x);
if(x<=m&&x>=0)
{
vis[x]++;
}
}
int res=0;
for(int i=0; i<m; i++)
{
if(vis[i]==0)res++;
}
res+=vis[m];
printf("%d\n",res);
}
}
相关文章推荐
- codeforces 862A Mahmoud and Ehab and the MEX
- CodeForces 862A Mahmoud and Ehab and the MEX
- codeforces 862A Mahmoud and Ehab and the MEX
- Codeforces - 862A Mahmoud and Ehab and the MEX
- Codeforces 862A Mahmoud and Ehab and the MEX
- codeforces 862A 之 Mahmoud and Ehab and the MEX
- codeforces 862B (二分图 dfs )之 Mahmoud and Ehab and the bipartiteness
- Codeforces Round #435 (Div. 2) 之Mahmoud and Ehab and the MEX
- [Codeforces]862F - Mahmoud and Ehab and the final stage
- Codeforces Round #435 A. Mahmoud and Ehab and the MEX
- codeforces 862B - Mahmoud and Ehab and the bipartiteness
- Codeforces 862 B Mahmoud and Ehab and the bipartiteness(二分图染色)
- Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
- Mahmoud and Ehab and the MEX
- 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX
- Codeforces 862C - Mahmoud and Ehab and the xor(找规律)
- Codeforces Round #435 (Div. 2) A. Mahmoud and Ehab and the MEX(思路)
- codeforces 862B B. Mahmoud and Ehab and the bipartiteness
- A. Mahmoud and Ehab and the MEX
- Codeforces Round #435 (Div. 2) E. Mahmoud and Ehab and the function