zoukankan      html  css  js  c++  java
  • Codeforces Round #435 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.

    思路:
    桶排序。

    代码:

    #include <cstdio>
    #include <iostream>
    
    using namespace std;
    
    int board[105];
    
    int main(){
        int N,X;
        cin>>N>>X;
        for(int i=0 ; i<N ; i++){
            int mid;
            cin>>mid;
            board[mid] = 1;
        }
        int result = 0;
        for(int i=0 ; i<X ; i++){
            if(board[i] == 0)result++;
        }
        if(board[X])result++;
        cout<<result<<endl;
    
        return 0;
    }
    
  • 相关阅读:
    3个检测浏览器UserAgent信息的网站
    linux系统下配置网桥(CentOS 5.5)
    squid封禁不带UserAgent的请求
    iptables透明网桥无法使用透明代理错误
    Squid修改用户浏览器的Useragent信息
    MySQL主从复制(MasterSlave)与读写分离(MySQLProxy)实践
    js中格式化时间
    js获取当前月的第一天和最后一天
    JS String.toDate
    Js获取当前日期时间及其它操作
  • 原文地址:https://www.cnblogs.com/vocaloid01/p/9514255.html
Copyright © 2011-2022 走看看