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++】
1 #include<cstdio> 2 #include <algorithm> 3 int main(){ 4 int t, n, i, data[1005]; 5 while (~scanf("%d", &t)){ 6 while (t--){ 7 for (i = scanf("%d", &n); i <= n; ++i) scanf("%d", &data[i]); 8 std::sort(data, data + n + 1); 9 for (i = data[0] = 0; i < n && data[i + 1] - data[i] < 2; ++i); 10 printf("%d ", ++data[i]); 11 } 12 } 13 return 0; 14 }