首页 > 其他 > 详细

A-Mex Query-2018年第二届河北省大学生程序设计竞赛

时间:2019-05-01 19:36:54      阅读:301      评论:0      收藏:0      [点我收藏+]

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
nn
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年第二届河北省大学生程序设计竞赛

原文:https://www.cnblogs.com/-yjun/p/10800473.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!