QLUACM Elimination For 2021 ACM Shandong Province Programming Contest (Clone) A

A. Special Week With Positive Integers

Description
Please notice the shortage of the Memory limit!

Special Week is now just wondering the minimum positive integer which is not in the integer sequence. For example, if the sequence is [2,4,3,4] then the answer is obviously 1, if the sequence is [1,2,3,4] then the answer is obviously 5.

Please notice that there also are some negative integers in the sequence.

So, just given Special Week one integer sequence of nn integers. Please help her to find the minimum positive integer without the sequence.

Input
The first line contains one positive integer n(1≤n≤10 6 ), indicating the length of the sequence.
The second line contains nn integers a[i](−10 ^18 ≤a[i]≤10 ^18 ), the element in the sequence.

Output
One integer, the minimum positive integer without the sequence.

Examples
input
4
2 4 3 4
output
1
input
4
1 2 3 4
output
5
input
4
-1 -2 -3 -4
output
1

AC code

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long int LL;
const int N=1e6+10;
LL q[N];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)	cin>>q[i];
	sort(q,q+n);
	if(q[n-1] <1)	{
		printf("1");
		return 0;
	}
	else if(q[0] >1){
		printf("1");
		return 0;
		}
		else{
			int i;
			for(i=0;i<n;i++){
				if(q[i]<1)	continue;
				else{
					if(q[i]>1 && q[i-1] <1){
						printf("1");
						return 0;
					}
					if(q[i]+1 != q[i+1]){
						cout<<q[i]+1<<endl;
						return 0;
					}				
				}
			}
			if(i == n)	cout<<q[i-1]+1<<endl;
		}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值