模拟——Next Test

Next Test

题面翻译

题面描述

给出 n n n 个互不相同的整数 a i a_i ai ,从小到大找第一个没有出现过的整数。

输入格式

第一行一个正整数 n n n ,之后是 n n n 个整数 a i a_i ai

输出格式

一个整数 x x x ,即第一个没有出现过的整数。

数据范围与约定

1 ≤ n ≤ 3000 1\leq n\leq 3000 1n3000

1 ≤ a i ≤ 3000 1\leq a_i\leq 3000 1ai3000

题目描述

«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.

You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.

输入格式

The first line contains one integer $ n $ ( $ 1<=n<=3000 $ ) — the amount of previously added tests. The second line contains $ n $ distinct integers $ a_{1},a_{2},…,a_{n} $ ( $ 1<=a_{i}<=3000 $ ) — indexes of these tests.

输出格式

Output the required default value for the next test index.

样例 #1

样例输入 #1

3
1 7 2

样例输出 #1

3

代码

#include<iostream>

using namespace std;

const int N = 3e5+10;

bool st[N];
int w[N];
int n;

int main(){
    cin>>n;
    
    for(int i=1;i<=n;i++){
        cin>>w[i];
        st[w[i]]=true;
    }
    
    for(int i=1;i<=N;i++){
        if(!st[i]){
            cout<<i;
            break;
        }
    }
    
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

green qwq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值