Codeforces 862A Mahmoud and Ehab and the MEX
2017-09-20 20:34
459 查看
题目链接:CF-862A
每日一水题,健康一辈子。求一个含有n个非负整数的集合的mex,其中mex定义为该集合中没有出现的最小非负整数。其中有对集合有两种合法操作,一种是添加某个非负整数,一种是删除某个非负整数,问最小操作数可以使得集合的mex=x。
注意特判mex=0。
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <string.h> using namespace std; int main() { int n, mex; scanf("%d%d", &n, &mex); bool temp[105]; memset(temp, false, sizeof(temp)); for (int i = 0;i < n;++i) { int v; scanf("%d", &v); temp[v] = true; } if (mex > 0) { int ans=0; for (int i = 0;i < mex;++i) { if (!temp[i]) ans++; } if (temp[mex]) ans++; printf("%d\n", ans); } else { if (temp[0]) printf("1\n"); else printf("0\n"); } //system("pause"); return 0; }
相关文章推荐
- 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 --- Mahmoud and Ehab and the MEX
- 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 Round #435 (Div. 2) A. Mahmoud and Ehab and the MEX(思路)
- A. Mahmoud and Ehab and the MEX
- codeforces 862B B. Mahmoud and Ehab and the bipartiteness
- codeforces 862B (二分图 dfs )之 Mahmoud and Ehab and the bipartiteness
- Codeforces 862C - Mahmoud and Ehab and the xor(找规律)
- Codeforces Round #435 (Div. 2) 之Mahmoud and Ehab and the MEX
- [Codeforces]862F - Mahmoud and Ehab and the final stage
- Codeforces Round #435 (Div. 2): C. Mahmoud and Ehab and the xor