http://115.28.76.232/problem?pid=1096
签到
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 128000/64000 KB (Java/Others)
Problem Description
BUAA-SCSE 新家族又要迎来新的同学了。这次的妹子颇多,足足有n人之多(1<=n<=10^6),她们每个人的学号都是1~2*10^9 内的一个整数。
董适早早地就掌握了她们每个人的学号,并且知道她们之中有一个人去幽会男朋友了!!!!
董适统计了在场所有妹子的学号,他想知道,哪个人没来?
董适早早地就掌握了她们每个人的学号,并且知道她们之中有一个人去幽会男朋友了!!!!
董适统计了在场所有妹子的学号,他想知道,哪个人没来?
Input
第一行是一个整数n,代表这个大班一共有n只妹纸
以下n行每行一个整数,代表每只妹纸的学号
以下n-1行每行一个整数,代表每只来了的妹纸的学号
以下n行每行一个整数,代表每只妹纸的学号
以下n-1行每行一个整数,代表每只来了的妹纸的学号
Output
输出没来的妹纸的学号。
Sample Input
3 10061061 10061023 10061201 10061061 10061023
Sample Output
10061201
这道题,用两重循环时,超时。。又学号的数比较大。。所以一个标记不行。。即将学号拆成两半标记。。
#include<cstdio>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
const int M = 1000000+5;
int a[M];
int b[M];
int c[M];
int d[M];
int main()
{
int n;
int cont=0;
scanf("%d", &n);
memset(c, 0, sizeof(c));
memset(d, 0, sizeof(d));
for(int i=0; i<n; i++)
{
scanf("%d", &a[i]);
c[a[i]/10000]++;
d[a[i]%10000]++;
}
for(int i=0; i<n-1; i++)
{
scanf("%d", &b[i]);
c[b[i]/10000]--;
d[b[i]%10000]--;
}
for(int i=0; i<M; i++)
{
if(c[i])
printf("%d",i);
if(d[i])
printf("%d\n",i);
}
return 0;
}
看解题报告还有一种运用异或运算的方法:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n) == 1)
{
int ans = 0;
int a;
for(int i = 0;i < 2*n-1;i++)
{
scanf("%d",&a);
ans ^= a;
}
printf("%d\n",ans);
}
return 0;
}