FJNU 1152 Fat Brother And Integer(胖哥与整数)

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\n", ++data[i]);
11         }
12     }
13     return 0;
14 }


 

转载于:https://www.cnblogs.com/Simon-X/p/5414183.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值