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. redis连接池操作

    /** * @类描述 redis 工具 * @功能名 POJO * @author zxf * @date 2014年11月25日 */public final class RedisUtil { p ...

  2. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  3. putty完全使用手册--多窗口---git提交---连接数据库--自动日志显示

    01 putty dev 192.168.3.38 02 cd /home/gongfu/tripb/cranedev02.1 git status git add git commit git pu ...

  4. Linux help websites

    FAQ

  5. Infix to posfix 自己写stack,没有()

    #include<iostream> #include<string> using namespace std; template<typename Type> s ...

  6. 从零开始学Axure原型设计(入门篇)

    如果说Sketch是最美.最简洁的设计软件,那么Axure就是最强大的原型制作软件.Axure不仅能制作静态的视觉稿.页面,还能添加交互动作,是进行原型设计的最佳软件之一.虽然Axure的学习曲线比较 ...

  7. 理解 Storm 拓扑的并行度(parallelism)概念

    组成:一个运行中的拓扑是由什么构成的:工作进程(worker processes),执行器(executors)和任务(tasks)! 在一个 Storm 集群中,Storm 主要通过以下三个部件来运 ...

  8. 利用scrollTop 制作图片无缝滚动

    <!doctype html><title>javascript无缝滚动 by 司徒正美</title><meta charset="utf-8&q ...

  9. NOIP2011-普及组复赛-第二题-统计单词数

    题目描述 Description 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数.  现在,请你编程实现这一功能,具体要求是:给 ...

  10. Hash算法冲突解决方法分析

    采用开放定址法处理散列表的冲突时,其平均查找长度?  高于链接法处理冲突 低于二分查找 开放定址法:一旦发生冲突,就去寻找下一个空的散列地址,只要散列地址够大,空的地址总会找到 链地址法: 一旦发生冲 ...