A. Mahmoud and Ehab and the MEX
来源:互联网 发布:网络信息安全宣传语 编辑:程序博客网 时间:2024/06/03 16:24
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?
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.
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
5 30 4 5 6 7
2
1 00
1
5 01 2 3 4 5
0
For the first test case Dr. Evil should add 1 and 2 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 the MEX of it is 0.
In the third test case the set is already evil.
解题说明:此题是一道数学题,统计出未出现的数字个数即可。
#include<cstdio>#include<iostream>#include<string>#include<cstring>using namespace std;int main(){int a[109];int n, x, i, j, k = 0, m = 0;scanf("%d%d", &n, &x);for (i = 0; i < n; i++){scanf("%d", &a[i]);}for (i = 0; i<n; i++){if (a[i] == x) {k = k + 1;}if (a[i]<x) {m++;}}k = k + (x - m);printf("%d\n", k, m);return 0;}
- A. Mahmoud and Ehab and the MEX
- Codeforces Round #435 A. Mahmoud and Ehab and the MEX
- Codeforces Round #435 A. 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
- 862A. Mahmoud and Ehab and the MEX
- 862A Mahmoud and Ehab and the MEX (水)
- CF 862A. Mahmoud and Ehab and the MEX
- codeforces 862A 之 Mahmoud and Ehab and the MEX
- CodeForces 862A Mahmoud and Ehab and the MEX
- Mahmoud and Ehab and the MEX
- Codeforces --- Mahmoud and Ehab and the MEX
- Codeforces Round #435 (Div. 2) A. Mahmoud and Ehab and the MEX(思路)
- Codeforces Round #435 (Div. 2) 之Mahmoud and Ehab and the MEX
- Mahmoud and Ehab and the xor CodeForces
- Mahmoud and Ehab and the bipartiteness CodeForces
- Mahmoud and Ehab and the xor CodeForces
- 我的博客选择记
- JavaScript事件详解
- 第三周第二节课(第二章——线性表)
- numpy 使用
- 5.0 Android 中多线程的用法大全
- A. Mahmoud and Ehab and the MEX
- STM32单片机学习详细局部介绍笔记
- 面向对象上(重点)
- hdu4513完美(马拉车模板题)
- bzoj2096 [Poi2010]Pilots
- SQL动态行转列
- Android 6.0 运行时权限处理完全解析
- [BZOJ1907]树的路径覆盖(贪心)
- 数据结构单链表创建(头插法,尾插法)java/c/c++