5 1 1 3 2 2 3 1 2 1 0
3 2use scanf to avoid Time Limit ExceededHintHint
| Exe.Time | Exe.Memory | Code Len. | ||||
| 889MS | 5324K | 506 B |
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[1000010];
int main(){
int n;
while(scanf("%d",&n),n){
int i,k;
for(i=0;i<n;++i){
scanf("%d",&a[i]);
}
sort(a,a+n);
k=0;
int ok=0;
for(i=1;i<n;++i){
if(a[i]^a[k]){
//printf("%d,%d\n",a[i],a[k]);
//printf("i-k=%d\n",i-k);
if((i-k)&1){
ok=1;
printf("%d\n",a[k]);
break;
}
else{
k=i;
}
}
}
if(!ok) printf("%d\n",a[n-1]);
}
return 0;
}
Exe.Time |
Exe.Memory | Code Len. | |||
| 748MS | 1404K | 187B |
#include<stdio.h>
int main(){
int n;
while(scanf("%d",&n),n){
int a,i,res=0;
for(i=0;i<n;++i){
scanf("%d",&a);
res=res^a;
}
printf("%d\n",res);
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
hdoj-2095-find your present (2)【位异或】
原文:http://blog.csdn.net/qq_18062811/article/details/47319867