MZL's xor

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

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)(1≤i,j≤n)
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
1≤m,z,l≤5∗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
 
Author
SXYZ
 
Source
AxorA=0 Axor0=A

i!=j时(Ai+Aj)xor(Ai+Aj)=0,剩下(A1+A1)xor(A2+A2)xor...xor(An+An),而Ai=(Ai−1∗m+z) mod l是产生随机数的函数,在一定长度下会出现循环,循环部分又可以约掉

 #include<cstdio>
#include<cstring>
bool b[];
int a[];
int main()
{
long long z, m, l;
int n, T;
scanf("%d", &T);
while (T--)
{
scanf("%d%lld%lld%lld", &n, &m, &z, &l);
int j, f, L, i;
memset(b, , sizeof(b));
L = ;
b[] = true;
a[] = ;
for (j = ;; j++)
{
L = (m*L + z) % l;//随机数产生函数,会有循环出现
if (b[L] == true) break;
b[L] = true;
a[j] = L;
}
int sum = ;
for (f = ; f < j; f++)
{
if (a[f] == L) break;
sum = sum ^ (a[f] << );
}
int cycle = j - f;
int div = (n - f) / cycle;
int mod = (n - f) % cycle;
if (div & )
{
for (i = f + mod; i < j; i++)
sum = sum ^ (a[i] << );
}
else
{
for (i = f; i < f + mod; i++)
sum = sum ^ (a[i] << );
}
printf("%d\n", sum);
}
}

hdu 5344 MZL's xor的更多相关文章

  1. hdu 5344 MZL's xor(数学之异或)

    Problem Description   MZL loves xor very much.Now he gets an array A.The length of A ≤i,j≤n) The xor ...

  2. HDU 5344 MZL's xor (多校)[补7月28]

    MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  3. HDU 5344 MZL's xor (水题)

    题意:给一个序列A,设序列B的中的元素有(Ai+Aj)(1≤i,j≤n),那么求B中所有元素的异或之和.而序列A是这样来的:A1=0,Ai=(Ai−1∗m+z) mod l. 思路:相同的元素异或结果 ...

  4. HDU 5344(MZL&#39;s xor-(ai+aj)的异或和)

    MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  5. hdoj 5344 MZL's xor

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5344 #include<stdio.h> #include<cstring> ...

  6. HDU 5351 MZL's Border (规律,大数)

    [HDU 5351 MZL's Border]题意 定义字符串$f_1=b,f_2=a,f_i=f_{i-1}f_{i-2}$. 对$f_n$的长度为$m$的前缀$s$, 求最大的$k$满足$s[1] ...

  7. hdu5344 MZL's xor(水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud MZL's xor Time Limit: 2000/1000 MS (Java/ ...

  8. MZL's xor

    MZL's xor Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total Sub ...

  9. Hdu 5352 MZL's City (多重匹配)

    题目链接: Hdu 5352 MZL's City 题目描述: 有n各节点,m个操作.刚开始的时候节点都是相互独立的,一共有三种操作: 1:把所有和x在一个连通块内的未重建过的点全部重建. 2:建立一 ...

随机推荐

  1. AnimatorController动画遮罩

    游戏中,我们的人物在某些时候,可能在一个时间点在做两件事,这样就需要同时播放两个动画,但我们肯定不能简单将其叠加,比如移动着开枪.攻击.挥手等等,那么在Unity中我们应该怎样实现这样的功能呢?且听我 ...

  2. 面试中有关C++的若干问题

    面试中有关C++的若干问题 By 晴天, 2014.5.16晚 什么是多态?简要说一下C++中的多态的概念. (1)定义:多态是指相同对象收到不同消息或者不同对象收到相同消息产生不同的行为. (2)C ...

  3. Gentoo:Xorg:Failed to load module "……" 问题

    错误描述: 安装完xorg-server后,startx启动桌面环境,出现缺少模块错误. Xorg:Failed to load module "--" 查看log: cat /v ...

  4. insertMany

    结果:

  5. Chapter 14_3 非全局的环境

    关于“环境”的一大问题在于它是全局的,任何对它的修改都会影响程序的所有部分. 例如:若安装一个元表用于控制全局变量的访问,那么整个程序都必须遵循这个规范. 当使用某个库时,没有先声明就使用了全局变量, ...

  6. UIAlertAction 弹出对话框9.0后有点变化

    ios 9.0后再用以前的UIAlertAction 已经不行了 被弃用了 改用这种方法了 UIAlertController *alertController = [UIAlertControlle ...

  7. 解决curl中errno为51和60的错误

    今天使用curl调用https接口的时候,发现接收不了数据 然后打印出curl_errno和curl_error发现是60错误,而生产环境是51错误 查了相关资料 加上两个参数就可以了 curl_se ...

  8. CentOS 7 多网卡绑定

    根据官方文档Red_Hat_Enterprise_Linux-7-Networking_Guide-en-US用nmcli做起来还是相当容易的.下面把俺的步骤贴下. 1.查看目前网卡的名称和状态.#n ...

  9. SqlSever 查询基本

    查询语句: SQL sever 查询语句: 1.查询所有字段: select * from UserInfo 2.条件筛选 (如查询UserInfo中的UserName) select UserNam ...

  10. hadoop pig入门总结

    在这里贴一个pig源码的分析,做pig很长时间没做笔记,不包含任何细节,以后有机会再说吧 http://blackproof.iteye.com/blog/1769219 hadoop pig入门总结 ...