概述
题意翻译
给出n个互不相同的整数a[i],从小到大找第一个没有出现过的整数。
输入:第一行一个正整数n,之后是n个整数a[i];
输出:一个整数x,即第一个没有出现过的整数。
1<=n<=3000 1<=a[i]<=3000
translated by 稀神探女
题目描述
«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 nn distinct integers a1,a2,...,an (1<=ai<=3000 ) — indexes of these tests.
输出格式:
Output the required default value for the next test index.
输入输出样例
输入样例#1
3 1 7 2
输出样例#1
3
思路
用桶排序,因为本题数据不大,可放心食用。
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int a[4001],i,n;
cin>>n;
for(i=1;i<=n;i++)
{
int now;
cin>>now;
a[now]++;//不知道为什么这么写的上网搜“桶排序”
}
i=1;
while(1)
{
if(a[i]==0)
{
cout<<i<<endl;
return 0;
}
i++;
}
}
最后
以上就是可爱饼干为你收集整理的CF27A Next Test (#模拟 -1.13)的全部内容,希望文章能够帮你解决CF27A Next Test (#模拟 -1.13)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复