zoukankan      html  css  js  c++  java
  • MZL's xor

    MZL's xor

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other)
    Total Submission(s) : 1   Accepted Submission(s) : 1
    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 ($A_i$+$A_j$)($1leq i,j leq n$)
    The xor of an array B is defined as $B_1$ xor $B_2$...xor $B_n$
     
    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$ $A_1=0$,$A_i=(A_{i-1}*m+z)$ $mod$ $l$ $1leq m,z,l leq 5*10^5$,$n=5*10^5$
     
    Output
    For every test.print the answer.
     
    Sample Input
    2 3 5 5 7 6 8 8 9
     
    Sample Output
    14 16
     题解:就是A数组可以得出,B数组是A[i]+A[j]组成的数组让求B1^B2^.......^Bn的值;
    代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 const int MAXN=5*1e5+10;
     4 long long A[MAXN],B[MAXN];
     5 int main(){
     6     int T,n,m,z,l;
     7     scanf("%d",&T);
     8     while(T--){
     9         scanf("%d%d%d%d",&n,&m,&z,&l);
    10         A[0]=0;
    11         long long ans=0;
    12         for(int i=1;i<n;i++){
    13             A[i]=(A[i-1]%l*m%l+z%l)%l;
    14             B[i]=A[i]+A[i];//因为相同的元素异或结果为0;所以A[i]+A[j] | A[j]+A[i]等于0;只剩相同元素之和的异或; 
    15             ans^=B[i];
    16         }
    17         printf("%lld
    ",ans);
    18     }
    19     return 0;
    20 }
  • 相关阅读:
    命令行下的curl使用详解
    升级python版本(从2.4.3到2.6.5)
    vim设置
    php中curl模拟post提交多维数组
    vim折叠设置
    基础算法4——归并排序
    总线类型
    主板分类
    网卡 接口类型
    基础算法3——直接选择排序和堆排序
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4872648.html
Copyright © 2011-2022 走看看