### ErdemKirez's blog

By ErdemKirez, 5 years ago, ,

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...

• +36

 » 5 years ago, # |   +1 i used this exact approach to solve OLOLO on SPOJ. :)
•  » » 5 years ago, # ^ |   0 I'm glad :)
 » 5 years ago, # |   0 Another Way , don't know any other people tried this way-http://codeforces.com/contest/440/submission/6823214
•  » » 5 years ago, # ^ |   0 I do: 6788270
•  » » 5 years ago, # ^ |   0 I do: 6790929
•  » » 5 years ago, # ^ |   0 This is a good solution too.
 » 5 years ago, # |   0 You can visit this entry. Similar problem. http://codeforces.com/blog/entry/12719
»
5 years ago, # |
-13

i am getting time limit exceeded for spoj prob OLOLO

Y??

# 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; }

•  » » 5 years ago, # ^ |   +3 Change cin, with scanf.