HDU5344 MZL's xor

首先做这道题这是够折腾的、足足提交了15次才总算AC了。。。

由于英语不好,理解题意时就出错了。题目原意是说将1~n范围内所有 B1 xor B2...全部异或、结果我却被(Ai+Aj)给误导了。傻傻地将他们两两求和和再进行异或

运算,结果就是很无情的WA了。。。我却还不知道怎么错了!还是英语太差啊。。。

好不容易搞懂题意,结果又被卡了数据。一道水题愣是折腾的我不要不要的!

由于a[i]+a[j]和a[j]+a[i]是相同的,异或值为0,所以真正有最后的结果还需要乘2。。。

总算明白了:以后做题千万不能光被测试实例迷了。用longlong  或__int64  就对了!

MZL's xor

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


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=(Ai1m+z)  mod  l
1m,z,l5105, n=5105
 

Output
For every test.print the answer.
 

Sample Input
 
   
2 3 5 5 7 6 8 8 9
 

Sample Output
 
   
14 16
 

Author
SXYZ
 

Source
2015 Multi-University Training Contest 5
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5421  5420  5419  5418  5417 
#include   
#include   
using namespace std;
long long n, m, z, l;

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%lld%lld%lld%lld", &n, &m, &z, &l);
        long long a = 0;
        long long k = 0;
        for (int i = 2; i <= n;i++)
        {
            k = (k *m + z) % l;
            a ^= (2 * k);
        }
        printf("%lld\n",a);
    }
    return 0;
}


5105

你可能感兴趣的:(HDU)