zoukankan      html  css  js  c++  java
  • A. Mahmoud and Ehab and the MEX

    A. Mahmoud and Ehab and the MEX
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    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 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.

    弄一个标记数组,然后合适补位就行了.

     1 #include <bits/stdc++.h>
     2 #define N 105
     3 using namespace std;
     4 int n,x;
     5 int k[N],m[N];
     6 int main(){
     7     cin>>n>>x;
     8     for(int i=0;i<n;i++){
     9       cin>>k[i];
    10       m[k[i]]=1;
    11     }
    12     int cnt=0;
    13     if(m[x]==1){
    14       cnt++;
    15     }
    16     for(int i=0;i<x;i++){
    17       if(m[i]==0)
    18         cnt++;
    19     }
    20     cout<<cnt<<endl;
    21   return 0;
    22 }
  • 相关阅读:
    Makefile 文件格式
    带你深入理解传递參数
    LeetCode OJ Basic Calculator II
    emacs 为什么找不到运行程序?
    iOS Dev (51)加急审核
    POJ 1159 Palindrome
    9.9递归和动态规划(十二)——小鸡吃米
    c++操作当前窗体句柄
    [Python]计算闰年时候出现的and和or优先级的问题以及短路逻辑
    静态代理模式
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/7562377.html
Copyright © 2011-2022 走看看