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. Linux shell 操作 postgresql,并设置crontab任务

    Linux shell 操作 postgresql:删除间隔日期的数据-删除指定日期的数据-vacuumdb 清理数据库 -清理日志 -定期执行脚本 *修改pg_hba.conf 设置本地连接无密码, ...

  2. H5 - 在线编辑制作

    [百度H5商店]http://h5.baidu.com/store [木疙瘩在在线制作]http://www.mugeda.com/ [百度在线制作工具]http://h5.baidu.com/ [易 ...

  3. ElasticSearch基础(4)-索引

    一.ES API常用规则 ES支持以Http协议的方式提供REST服务,以JSON格式发送请求返回响应. ES提供了大量的不管的数据操作,运维管理API,大量的api 这海量的api有一些通用的功能特 ...

  4. Docker技术学习

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://sofar.blog.51cto.com/353572/1598249 貌似Doc ...

  5. HashMap解惑

    HashMap中有一些我们容易忽视的点 1. 关于key的hash和equals public V put(K key, V value) { if (table == EMPTY_TABLE) { ...

  6. Openjudge-计算概论(A)-取石子游戏

    描述: 有两堆石子,两个人轮流去取.每次取的时候,只能从较多的那堆石子里取,并且取的数目必须是较少的那堆石子数目的整数倍.最后谁能够把一堆石子取空谁就算赢. 比如初始的时候两堆石子的数目是25和7 2 ...

  7. spring容器启动的加载过程(一)

    使用spring,我们在web.xml都会配置ContextLoaderListener <listener> <listener-class> org.springframe ...

  8. ubuntu切换到超级管理员权限

    默认情况下是无法切换的,需要给root用户设置上密码 mars@mars-LIFEBOOK-LH531:~$ sudo passwd root[sudo] password for mars: 输入新 ...

  9. redis高级实用特性(2)

    事务处理: redis对事务的支持目前还是比较简单,redis只能保证一个 client发起事务中的命令可以连续执行,而中间不会插入其他 client的命令,当一个client 在一个连接中发出mul ...

  10. MySQL-MHA高可用方案

    http://files.cnblogs.com/jimingsong/mha-mysql.pdf 此方案为一号店MySQL MHA高可用方案.备注.