HDU 5344 MZL's xor
来源:互联网 发布:淘宝店铺排行榜怎么看 编辑:程序博客网 时间:2024/05/01 14:03
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5344
题意:给出大小为n数组a,ai=(aj*m+z)%l (j=i-1,a0=0),数组b为所有的(ai+aj),问b1^b2^b3……是多少
思路:假设n=3,b1=(a1+a1),b2=(a1+a2),b3=(a1+a3),b4=(a2+a1),b5=(a2+a2),b6=(a2+a3)……
因为b2=b4,b2=b4……,而异或操作是满足交换律的,相同的数进行异或操作后等于0
所以最后可以化简为:b1^b2^b3……=0^b1^b5^b9=(a1+a1)^(a2+a2)^(a3+a3)
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define LL long longusing namespace std;LL a[500030];int main(){ int t,n,m,z,l; scanf("%d",&t); while (t--) { scanf("%d%d%d%d",&n,&m,&z,&l); int res=0; a[1]=0; for (int i=2;i<=n;i++) { a[i]=(a[i-1]*m+z)%l; res=res^(2*a[i]); } printf("%d\n",res); }}
0 0
- HDU 5344 MZL's xor
- HDU 5344 MZL's xor
- hdu 5344 MZL's xor
- hdu 5344 MZL's xor
- HDU 5344 MZL's xor
- Hdu-5344 MZL's xor
- HDU 5344 MZL's xor
- HDU 5344 多校赛1002 MZL's xor
- hdu 5344 MZL's xor(水)
- HDU 5344 MZL's xor(水题)
- Hdu 5344 MZL's xor (杂)
- 【HDU 5344 MZL's xor】+ 异或
- hdu 5334 MZL's xor
- HDU 5344(2015多校5)-MZL's xor(水题)
- hdu 5344 (多校联赛) MZL's xor --- 位运算
- HDU 5344 MZL's xor(异或运算)
- HDOJ 5344 MZL's xor 【math】
- 其他-HDOJ-5344-MZL's xor
- SQLserver2008,存储过程,游标的使用。
- 新的一天
- 全局变量EG、CG
- iOS 给TextView添加placeholder.
- Object-C Category和Extension的区别
- HDU 5344 MZL's xor
- 为什么有时可以在头文件可以定义变量,有时不行(变量重定义)。
- Sql_mode
- XML解析(pull解析)
- Java 乱码处理方案
- 在升序排序的数组中插入一个元素
- Java中wait和sleep区别
- XML解析(SAX解析)
- $.fn.extend()和$.extend()