我是靠谱客的博主 专注铅笔,这篇文章主要介绍【水hash】#27 A. Next Test,现在分享给大家,希望可以做个参考。

A. Next Test
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

«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.

Input

The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.

Output

Output the required default value for the next test index.

Sample test(s)
input
复制代码
1
2
3 1 7 2
output
复制代码
1
3


这道题是一个hash表的问题,可以作为理解hash的一道入门题

题意是说:给一系列互不相同的数字,从小到大找第一个没有出现的数字。

我们就可以开一个bool型(int型用0/1也是一个道理)的数组mark[i]来记忆i这个数字有没有出现过,然后读完了之后遍历,第一个false的就是所求的数字了

代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cmath> #include <cctype> #include <cstdio> #include <string> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) bool mark[3001]; int main() { memset(mark,false,sizeof(mark)); int n=0; cin>>n; for(int i=1;i<=n;i++) { int now; cin>>now; mark[now]=true; } for(int j=1;j<=n+1;j++) { //cout<<mark[j]; if(mark[j]==false) { cout<<j; return 0; } } return 0; }


最后

以上就是专注铅笔最近收集整理的关于【水hash】#27 A. Next Test的全部内容,更多相关【水hash】#27内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(76)

评论列表共有 0 条评论

立即
投稿
返回
顶部