862A. Mahmoud and Ehab and the MEX

来源:互联网 发布:流体力学分析软件 编辑:程序博客网 时间:2024/06/02 00:32

http://codeforces.com/problemset/problem/862/A

分三种情况讨论 x<t[0],x=t[0],x>t[0];

#include <bits/stdc++.h>using namespace std;int main(){    int n,x;    cin>>n>>x;    int t[n];    for(int i=0;i<n;i++) cin>>t[i];    sort(t,t+n);    if(x<t[0])    {        if(x==0) cout<<0;        else cout<<x;    }    if(x==t[0])    {        if(x==0) cout<<1;        else cout<<x+1;    }    if(x>t[0])    {        int fla=0;        for(int i=0;i<n;i++)        {            if(t[i]==x) fla=1;        }        if(x<t[n-1]&&fla==0)//在中间五相等        {            for(int i=0;i<n;i++)            {                if(t[i]<x&&t[i+1]>x)                {                    cout<<x-i-1;                    break;                }            }        }        if(x>t[n-1])        {            cout<<x-n;        }        if(x<=t[n-1]&&fla==1)        {            for(int i=0;i<n;i++)            {                if(t[i]==x)                {                    cout<<x-i+1;                    break;                }            }        }    }    return 0;}


原创粉丝点击