Status |
In/Out |
TIME Limit |
MEMORY Limit |
Submit Times |
Solved Users |
JUDGE TYPE |
|
stdin/stdout |
3s |
40960K |
1071 |
235 |
Standard |
In a interger sequence S there are N(N < 1000000) intergers, there is a initial number I(-2^31 < I <2^31), which is the minimun interger in S, and no two integers are the same. Now can you find the first lost interger L make the sequence is not consecutive. For example, S = { 1, -2, 2, 9, -1 }, then I = -2, and L = 0.
Input
For each case N is in the first line, and next N lines is the sequence S.
Output
Output L for each case in a single line.
Sample Input
5
1
-2
2
9
-1
Sample Output
0
不用走入排序的误区,
可以在线性的时间内完成。
先一趟循环,保存输入的值n[MAX],同时可找出最小的值,
再来一趟循环以此为基准对每个数进行标记,对每个出现的num,mark[num-min]=1;
然后
for(int i=0;;i++)
{if(mark[i]==0)
cout<<i+min;
break;
}
----
posted on 2009-07-19 14:18
luis 阅读(336)
评论(1) 编辑 收藏 引用 所属分类:
粗心题