CodeForces - 662A Gambling Nim

时间:2021-01-02 16:07:26

http://codeforces.com/problemset/problem/662/A

题目大意:

给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概率是在正面,各个卡牌独立。
求把所有卡牌来玩Nim游戏,先手必胜的概率。

(⊙o⊙)…由于本人只会在word文档里写公式,所以本博客是图片格式的。

CodeForces - 662A Gambling Nim

CodeForces - 662A Gambling Nim

Code

  

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
template<typename T>inline void read(T &x){
x=;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=*x+ch-'',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = ;
ll a[maxn],b[maxn],c[maxn],cnt;
#define lowbit(x) (x&-x)
int main(){
ll n,S=;read(n);
for(int i=;i<=n;++i){
read(a[i]);read(b[i]);
S^=a[i];a[i]^=b[i];
}
for(int i=;i<=n;++i){
for(int j=;j<=cnt;++j){
if(a[i] & lowbit(c[j])) a[i] ^= c[j];
}if(a[i] != ) c[++cnt] = a[i];
}
for(int i=;i<=cnt;++i){
if(S & lowbit(c[i])) S ^= c[i];
}
if(S != ) puts("1/1");
else{
ll x = 1LL<<cnt;
printf("%lld/%lld\n",x-,x);
}
getchar();getchar();
return ;
}