[ACdream原创群赛(12)のBUAA选拔赛]E:签到

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行每行一个整数,代表每只来了的妹纸的学号
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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值