zoukankan      html  css  js  c++  java
  • 洛谷 4932 洛谷10月月赛II T1 浏览器

    【题解】

      x xor y的结果在二进制下有奇数个1,等价于x与y在二进制下的1的个数之和为奇数,因为x xor y减少的1的个数一定是偶数(两个数这一位都为1,xor的结果为0,减少了2个1)

      那么答案就是序列中二进制下有奇数个1的数的个数 乘 二进制下有偶数个1的数的个数。

      因为n有1e7,暴力算每个数二进制下1的个数是不行的。我们需要预处理0~2^15的Popcount,把每个数掐成高低两段统计。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define LL long long
     5 #define rg register
     6 #define N 10000010
     7 using namespace std;
     8 int n,Popcount[40000],a,b,c,d,x,odd,even;
     9 inline int read(){
    10     int k=0,f=1; char c=getchar();
    11     while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    12     while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
    13     return k*f;
    14 } 
    15 int main(){
    16     for(rg int i=1;i<32767;i++) Popcount[i]=Popcount[i&(i-1)]+1;
    17     n=read(); a=read(); b=read(); c=read(); d=read(); x=read();
    18     for(rg int i=1;i<=n;i++){
    19         x=(1ll*a*x%d*x+1ll*b*x+c)%d;
    20         int tmp=Popcount[x>>15]+Popcount[x&32767];
    21         if(tmp&1) odd++; else even++;
    22     }
    23     printf("%lld
    ",1ll*odd*even);
    24     return 0;
    25 }
  • 相关阅读:
    SimpleCursorAdapter的使用
    sizeof和strlen的区别和联系总结
    设计模式-工厂方法模式
    Python第四章-字典
    Python第四章-字典
    Python第三章-字符串
    Python第三章-字符串
    Python 第二章-列表和元组
    Python 第二章-列表和元组
    设计模式-简单工厂模式
  • 原文地址:https://www.cnblogs.com/DriverLao/p/9837069.html
Copyright © 2011-2022 走看看