FJNU 1152 Fat Brother And Integer(胖哥与整数)
Time Limit: 1000MS Memory Limit: 257792K
【Description】 |
【题目描述】 |
Fat brother recently studied number theory, him came across a very big problem — minimum does not appear positive integer. Fat brother get n positive integers, he needs to find out the least a positive integer and the positive integer is not in his n positive integers. |
胖哥最近在学数论,他遇到了个重大问题— 最小未出现的正整数。胖哥有n个正整数,他需要找出不在这n个正整数中的最小正整数。 |
【Input】 |
【输入】 |
There are multiple test cases. The first line of input contains an integer T (T <= 25) indicating the number of test cases. For each test case: The first line contains a single integer n (1 <= n <= 1000) The second line contains n positive integer ai ( 1 <= ai <= 1000000000) |
多组测试用例。 第一行是一个整数T(T <= 25)表示测试用例的数量。对于每个测试用例: 第一行是一个正整数n(1 <= n <= 1000) 第二行有n个正整数 ai( 1 <= ai <= 1000000000) |
【Output】 |
【输出】 |
For each test case, output the minimum positive integer which didn’t appear in the n positive integer |
对于每个测试用例,输出不在这n个正整数里出现的最小正整数 |
【Sample Input - 输入样例】 |
【Sample Output - 输出样例】 |
2 5 1 2 3 4 5 5 1 100 101 102 103 |
6 2 |
【题解】
最多就100个,直接暴力掉吧,注意下重复的元素就行了。
【代码 C++】
#include<cstdio>
#include <algorithm>
int main(){
int t, n, i, data[];
while (~scanf("%d", &t)){
while (t--){
for (i = scanf("%d", &n); i <= n; ++i) scanf("%d", &data[i]);
std::sort(data, data + n + );
for (i = data[] = ; i < n && data[i + ] - data[i] < ; ++i);
printf("%d\n", ++data[i]);
}
}
return ;
}