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
#include
#include
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."<         else
        {
            for(j=0;j                 if(k>=a[j]&&k<=b[j]&&(k-a[j])%c[j]==0)//找有几张传单
                sum++;
            cout<         }


    }
    return 0;
}

你可能感兴趣的:(操作符)