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 閱讀(345)
評論(1) 編輯 收藏 引用 所屬分類:
粗心題