zoukankan      html  css  js  c++  java
  • 【题解】 Codeforces 662A Gambling Nim (线性基)

    662A,戳我戳我

    Solution:

    • 我们先取(ans=a[1] igoplus a[2] igoplus ... igoplus a[n]),然后我们定义(c[i]=a[i] igoplus b[i]),我们就可以知道每异或一个(c[i]),就是更换选取(a[i],b[i]),这里很好想。
    • 然后我们要处理出(c[i]),中有多少子集异或和为(ans),这样异或出来总和为(0),这个我们就可以用线性基了。
    • 然后后面求子集我还是没有太弄懂,看了题解也有点蒙,先留一个坑
    • 题解

    Code:

    //It is coded by Ning_Mew on 5.31
    #include<bits/stdc++.h>
    #define LL long long
    using namespace std;
    
    const int maxn=5e5+7;
    
    int n,tot=0;
    LL a[maxn],b[maxn],c[maxn],x[maxn],ans=0;
    
    bool push(LL s){
      for(int i=63;i>=0;i--){
        if((s>>i)&1){
          if(x[i]){s=s^x[i];}
          else {x[i]=s;return true;}
        }
      }return false;
    }
    LL q_pow(LL xx,LL t){
      LL re=1;
      while(t){
        if(t%2){re=re*xx;}
        xx=xx*xx;t=t/2;
      }return re;
    }
    int main(){
      scanf("%d",&n);
      for(int i=1;i<=n;i++){
        scanf("%I64d%I64d",&a[i],&b[i]);
        c[i]=a[i]^b[i];ans^=a[i];
      }
      for(int i=1;i<=n;i++){
        if(push(c[i]))tot++;
      }
      if(push(ans)){printf("1/1
    ");return 0;}
      else{
        printf("%I64d/%I64d
    ",q_pow(2,tot)-1,q_pow(2,tot));
      }
      return 0;
    }
    
    

    博主蒟蒻,随意转载。但必须附上原文链接:http://www.cnblogs.com/Ning-Mew/,否则你会终生找不到妹子!!!

  • 相关阅读:
    移动端调试Vconsole
    Vue-返回顶部
    Vue-封装loading
    Vue-水印封装
    Vue-封装scroll触底
    微信小程序-图片上传
    前端面试题(2)
    前端常见面试题
    服务端渲染(SSR)和客户端(CSR)渲染的区别
    什么是模块化?模块化开发的好处
  • 原文地址:https://www.cnblogs.com/Ning-Mew/p/9118745.html
Copyright © 2011-2022 走看看