Codeforces Round #435 (Div. 2), problem: (A) Mahmoud and Ehab and the MEX

题意:给你n个数再给一个数字K,问你最少多少个操作能让K前的数字都存在,K不存在。

题解:先删除所有的K,再补完前面缺少的数字。

 

代码:

#include <cstdio>
int N, cnt[101], K, O;
int main()
{
 scanf("%d%d", &N, &K);
 for (int i = 0, x; i < N; i++)
 {
  scanf("%d", &x);
  if (x == K)
   O++;
  else if (x < K)
   cnt[x] = 1;
 }
 for (int i = 0; i < K; i++)
  if (!cnt[i])
   O++;
 printf("%d\n", O);
 return 0;
}

posted @ 2017-09-20 13:43  LMissher  阅读(81)  评论(0编辑  收藏  举报