Accept: 5413 Submit: 25842
Time Limit: 1000 mSec Memory Limit : 65536 KB
Problem Description
An array of length n, with address from 1 to n inclusive, contains entries from the set {1,2,...,n-1} and there's exactly two elements with the same value. Your task is to find out the value.
Input
Input contains several cases.
Each case includes a number n (1<n<=10^6), which is followed by n integers.
The input is ended up with the end of file.
Each case includes a number n (1<n<=10^6), which is followed by n integers.
The input is ended up with the end of file.
Output
Your must output the value for each case, one per line.
Sample Input
21 141 2 3 2
Sample Output
12
Source
IBM Challenge 2004.1
int sum[1000000]={0};
int main(int argc, const char * argv[]) {
long i,j,n;
while(scanf("%ld",&i)!=EOF){
for(j=0;j之前疯狂超时报错,后规范写法将
while(scanf("%ld",&i))
改为
while(scanf("%ld",&i)!=EOF)
最终完成
本文介绍了一个算法问题:在一个长度为n的数组中找到重复的数值。数组中的元素来自集合{1,2,...,n-1}
2万+

被折叠的 条评论
为什么被折叠?



