fzu 1001
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.
Output
Your must output the value for each case, one per line.
Sample Input
2
1 1
4
1 2 3 2
Sample Output
1
2
为什么超时??
#include <iostream>
using namespace std;
int main()
{
int b,n,i,m,s;
while(scanf("%d",&n))
{
s=0;
m=0;
for(i=0;i<n;i++)
{
scanf("%d",&b);
s=s+b;
m+=i;
}
printf("%d\n",s-m);
}
return 0;
}