A-Mex Query-2018年第二屆河北省大學生程序設計競賽
阿新 • • 發佈:2019-05-01
clear int sign num unsigned names ati sin 輸入
nn
n non-negative integers
aia_i
a
i
Give
nn
n non-negative integers, please find the least non-negative integer that doesn’t occur in the
nn
n numbers.
輸入:
The first line is an integer
TT
T, representing the number of test cases.
For each test case:
The first line of each test case is an integer
nn
n.
The second line of each test case are
n non-negative integers
aia_i
a
i
題意:給你n個數,找出缺失的第一個非負整數.
題解:用map標記已經出現過數,然後從 0 到 1<<31枚舉,
#include <bits/stdc++.h> using namespace std; typedef long long ll; map<unsigned,int> m; int main(){ int t; cin>>t; while(t--){ m.clear(); int n; cin>>n; unsigned tmp; for(int i=1;i<=n;i++){ scanf("%u",&tmp); m[tmp]=1; } unsigned i=0; while(i<=(1<<31)){ if(m[i]==0){ printf("%u\n",i); break; } i++; } } return 0; }
A-Mex Query-2018年第二屆河北省大學生程序設計競賽