Hi everyone! I have a solution for 440A, and I want to share it.
FOR(i,1,n-1)
{
cin >> x;
t^=x;
t^=i;
}
t^=n;
cout << t << endl;
The proof is,
x xor x = 0
Make xor to all elements in array, and make xor all number 1 to n. The value is our answer. Because if one number is xor twice, number doesn't change anything.
Sorry for my poor English...
i used this exact approach to solve OLOLO on SPOJ. :)
I'm glad :)
Another Way , don't know any other people tried this way-
http://mirror.codeforces.com/contest/440/submission/6823214
I do: 6788270
I do: 6790929
This is a good solution too.
You can visit this entry. Similar problem. http://mirror.codeforces.com/blog/entry/12719
i am getting time limit exceeded for spoj prob OLOLO
Y??
include
include
include
using namespace std; int main() { int N; cin >> N; int tmp, result = 0; for (int i = 0; i < N; i++) { cin >> tmp; result ^= tmp; } cout << result; return 0; }
Change cin, with scanf.