FJNU-1152 Fat Brother And Integer

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.

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)

Output

For each test case, output the minimum positive integer which didn’t appear in the n positive integer

 Sample Input

2

5

1 2 3 4 5

5

1 100 101 102 103

Sample Output

6

2



即给定数组,输出未出现在该数组中最小的数,注意要先排序,sort的用法。

#include <cstdio>
#include <algorithm>

int main(void)
{
    int t, n;
    int num[1100];
    while(scanf("%d", &t) != EOF)
    {
        while(t--)
        {
            scanf("%d", &n);
            for(int i = 0; i < n; i++)
            {
                scanf("%d", &num[i]);
            }
            std::sort(num, num+n);
            int i = 0;
            if(num[i] > 1)
            {
                printf("1\n");
            }
            else
            {
                for(; i < n-1; i++)
                {
                    if(num[i+1]-num[i] > 1)
                        break;
                }
                printf("%d\n", num[i]+1);
            }
        }
    }
    return 0;

}


STL中自带了排序函数——sort, 通常其表示为 sort(begin, end),即排序的区间、范围(需包涵<algorithm>和std)。

int main(void)
{
  int a[5] {1, 4, 6, 2, 3};
  std::sort(a, a+5);
  return 0;
}

sort默认排序方式为从小到大排列,要想从大到小排列,可以自定义一个函数,做为 sort 的第三个参数。

int main(void)
{
    bool func(int, int);

    std::sort(a, a+5, func);

    return 0;
}    

bool func(int a, int b)
{
    return a>b;
}
时间: 2024-08-28 10:11:12

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 l

FJNU 1154 Fat Brother And His Love(胖哥与女神)

FJNU 1154 Fat Brother And His Love(胖哥与女神) Time Limit: 2000MS   Memory Limit: 257792K [Description] [题目描述] As we know, fat Brother and his goddess is in a same city. The city is consist of N locations and the N locations is connected by M roads. Fat B

FJNU 1155 Fat Brother’s prediction(胖哥的预言)

FJNU 1155 Fat Brother’s prediction(胖哥的预言) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目描述] Fat Brother is a famous prophet, One day he get a prediction that disaster will come after X days. He is too nervous that sudden die. Fortunatel

FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术)

FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目描述] Fat Brother is a powerful magician. Both he and his enemy has N soldiers and each soldier has IQ. When two soldier is in PK, the one whose IQ

FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)

FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目描述] Fat Brother is a Great warrior(战士) and he has a powerful weapons named “Gorehowl”. Firstly it can cause 7 damage points to the other side, but it

FJNU 1153 Fat Brother And XOR(胖哥与异或)

Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目描述] Fat brother had master ACM, recently he began to study the operation of XOR (the operation “^”). He thought of a very interesting question: select arbitrary k positive integers from the

FJNU-1159 Fat Brother’s new way

Description I bet, except Fat Brothers, all of you don't like strange way to show integers , he is really like this way to showing integers: 1 -> 'A' 2 -> 'B' --. 26 -> 'Z' 27 -> 'AA' 28 -> 'AB' --. Unfortunately, Fat Brother's mathematics 

FZU 2150 Fire Game(点火游戏)

p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h2 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: left; font-family: 宋体; font-weight: bold; font-size: 18.0000pt } h3 {

FZU 2148 Moon Game 判断凸边形

点击打开链接 Problem 2148 Moon Game Accept: 512    Submit: 1419 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a k