码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5344

时间:2015-08-04 21:02:48      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

MZL‘s xor

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 208    Accepted Submission(s): 157


Problem Description
MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1i,jn)
The xor of an array B is defined as B1 xor B2...xor Bn
 

Input
Multiple test cases, the first line contains an integer T(no more than 20), indicating the number of cases.
Each test case contains four integers:n,m,z,l
A1=0,Ai=(Ai?1?m+z) mod l
1m,z,l5?105,n=5?105
 

Output
For every test.print the answer.
 

Sample Input
2 3 5 5 7 6 8 8 9
 

Sample Output
14 16
 

Source



可以发现,a[i]+a[j]和a[j]+a[i]是相同的,异或值为0,所以真正有贡献的就是两倍的本身。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<math.h>
#include<algorithm>
using namespace std;
#define N 500005
typedef long long ll;
ll a[N],b[N];
int len;
int main()
{
    int i,j,n,m,t;
    scanf("%d",&t);
    while(t--)
    {
        len=0;
        int z,l;
        scanf("%d%d%d%d",&n,&m,&z,&l);
        a[1]=0;
        for(i=2; i<=n; i++)
            a[i]=(a[i-1]*m+z)%l;
        int sum=a[1];
        /*
        for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
        {
            b[len++]=a[i]+a[j];
        }
        for(i=1;i<len;i++)
        {
            b[i]=b[i-1]^b[i];
        }
        cout<<b[len-1]<<endl;
        */
        for(i=2; i<=n; i++)
        {
            a[i]=a[i-1]^a[i];
        }
        printf("%lld\n",a[n]*2);
    }
}

 
 

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5344

标签:

原文地址:http://blog.csdn.net/sky_miange/article/details/47281787

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!