That Italy has been very obvious, but I was first put to use violence discrete digital method, to keep the value of the subscript number after the discrete then there have been several
1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<map> 6 using namespace std; 7 const int maxn=10000000; 8 map<int,int>r; 9 int main() 10 { 11 //printf("%d\n",0^1^2^3); 12 int n,sum,a; 13 sum=0; 14 scanf("%d",&n); 15 for(int i=1;i<=n;++i) 16 { 17 scanf("%d",&a); 18 r[a]++; 19 //printf("%d\n",r[a]); 20 if(r[a]%2) 21 sum^=a; 22 else if((r[a]-1)!=0) 23 sum^=a; 24 } 25 printf("%d\n",sum); 26 return 0; 27 }
But Memory Limit
Then I went to all digital ordering, so do not keep up, because the drained order, the same numbers together
1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<map> 6 using namespace std; 7 typedef long long ll; 8 const int maxn=10000005; 9 int v[maxn]; 10 int main() 11 { 12 int n,sum=0; 13 scanf("%d",&n); 14 for(int i=1; i<=n; ++i) 15 { 16 scanf("%d",&v[i]); 17 } 18 //sort(v+1,v+1+n); 19 int ci=0; 20 v[0]=0; 21 for(int i=1; i<=n; ++i) 22 { 23 if(v[i]!=v[i-1]) 24 { 25 if(ci!=0 && ci%2) 26 sum^=v[i-1]; 27 ci=1; 28 } 29 else ci++; 30 } 31 //printf("%d\n",ci); 32 if(ci!=0 && ci%2) 33 sum^=v[n]; 34 printf("%d\n",sum); 35 return 0; 36 }
But it Memory Limit
I sort remove sort again, try to test a handful of results still over (look ignorant!)
1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<map> 6 using namespace std; 7 typedef long long ll; 8 const int maxn=10000005; 9 int main() 10 { 11 int n,sum=0,a1,a2,b; 12 scanf("%d",&n); 13 scanf("%d",&a1); 14 b=1; 15 for(int i=2; i<=n; ++i) 16 { 17 scanf("%d",&a2); 18 if(a1==a2) ++b; 19 else 20 { 21 if(b!=0 && b%2) sum^=a1; 22 b=1; 23 a1=a2; 24 } 25 } 26 if(b!=0 && b%2) sum^=a1; 27 printf("%d\n",sum); 28 return 0; 29 }
After the game finished, listen to them data that questions just need to have all the input XOR again on it, because even if a number appears several times, then XOR will even number of times, we know that a number or an even number of exclusive no exclusive or equivalent. It fits the meaning of problems!
This code will not give up
This time I was thinking, why not add sort that I can live, but also the same principle
Data like 12,332,464
My code is not exclusive or 3, but different or two, but exclusive or twice or equivalent 2. Therefore, there is no XOR