2013icpc网络赛长春赛区J题(Flyer)

The new semester begins! Different kinds of student societies are all trying to advertise themselves, by giving flyers to the students for introducing the society. However, due to the fund shortage, the flyers of a society can only be distributed to a part of the students. There are too many, too many students in our university, labeled from 1 to 2^32. And there are totally N student societies, where the i-th society will deliver flyers to the students with label A_i, A_i+C_i,A_i+2*C_i,…A_i+k*C_i (A_i+k*C_i<=B_i, A_i+(k+1)*C_i>B_i). We call a student "unlucky" if he/she gets odd pieces of flyers. Unfortunately, not everyone is lucky. Yet, no worries; there is at most one student who is unlucky. Could you help us find out who the unfortunate dude (if any) is? So that we can comfort him by treating him to a big meal!

题意很简单,每个社团给特定学号区间内的人发传单,有步长,问最终谁获得的传单数是奇数的,输出那个人的学号和传单书(或者都是偶数0.0)

因为是2^31次,所以数组开不下,这里采用异或操作符,我们把每次社团发给学生的学号进行异或操作,因为异或有个特点,自己异或自己是0,0再异或自己还是自己,所以我们可以在每一次的询问下不停地异或,因为题目上说最终只有一个人是奇数的,所以最终异或得到的值就是那个学生的学号,或者直接是0,即没有。然后我们用这个学生的学号重新搜一遍找被发了几次就可以了。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    //freopen("E:\\in.txt","r",stdin);
    int n;
    while(scanf("%d",&n)!=EOF)
    {int a[20010],b[20010],c[20010];
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        int i;
        int  j=0;
        int temp=n;
        int k=0;
        while(n--)
        {
            scanf("%d%d%d",&a[j],&b[j],&c[j]);//不要用cin,太慢了。。。这里TLE了好久才发现
            for(i=a[j]; i<=b[j]; i=i+c[j])
            k^=i;//异或操作
            j++;
        }
        int sum=0;
        if(k==0)
        cout<<"DC Qiang is unhappy."<<endl;
        else
        {
            for(j=0;j<temp;j++)
                if(k>=a[j]&&k<=b[j]&&(k-a[j])%c[j]==0)//找有几张传单
                sum++;
            cout<<k<<" "<<sum<<endl;
        }


    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值