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

题目大意:

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

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

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 ;
}

CodeForces - 662A Gambling Nim的更多相关文章

  1. 【题解】 Codeforces 662A Gambling Nim (线性基)

    662A,戳我戳我 Solution: 我们先取\(ans=a[1] \bigoplus a[2] \bigoplus ... \bigoplus a[n]\),然后我们定义\(c[i]=a[i] \ ...

  2. CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)

    As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initi ...

  3. 【CF662A】Gambling Nim 线性基

    [CF662A]Gambling Nim 题意:n长卡牌,第i张卡牌正面的数字是$a_i$,反面的数字是$b_i$,每张卡牌等概率为正面朝上或反面朝上.现在Alice和Bob要用每张卡牌朝上的数字玩N ...

  4. codeforces 15C. Industrial Nim

    题目链接:http://codeforces.com/problemset/problem/15/C $NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多. 考虑利用异或的性 ...

  5. Codeforces 15C Industrial Nim 简单的游戏

    主题链接:点击打开链接 意甲冠军: 特定n 下列n行,每一行2的数量u v 表达v礧:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先依据Nim的博弈结论 把全部数都异或一下, ...

  6. codeforces - 15C Industrial Nim(位运算+尼姆博弈)

    C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...

  7. Codeforces - 662A 思路巧妙的异或

    题意:给你\(n\)堆石子玩尼姆博弈,每堆石子可以是\(a_i\)也可以是\(b_i\),选择概率相等且每堆选择相互独立,求先手必胜(异或不为0)的概率 首先需要找出一种优雅的策略表示方法(利用异或的 ...

  8. Codeforces 1162E Thanos Nim(博弈)

    一道有意思的博弈题.首先我们考虑一种必败情况,那就是有一方拿光了一堆石子,显然对方是必胜,此时对方可以全部拿走其中的n/2,那么轮到自己时就没有n/2堆,所以此时是必败态.我们先对所有石子堆sort, ...

  9. CodeForces - 1162E Thanos Nim (博弈论)

    Alice and Bob are playing a game with nn piles of stones. It is guaranteed that nn is an even number ...

随机推荐

  1. 9.6 MongoDB一

    目录:ASP.NET MVC企业级实战目录 9.6.1 MongoDB简介 MongoDB是一个高性能,开源,无模式的文档型数据库,是当前NoSql数据库中比较热门的一种.它在许多场景下可用于替代传统 ...

  2. BroadcastReceiver几种常见监听

    1.BroadcastReceiver监听拨号 <intent-filter android:priority="1000" > <action android: ...

  3. 9.2.4 .net core 通过ViewComponent封装控件

    我们在.net core中还使用了ViewComponent方式生成控件.ViewComponent也是asp.net core的新特性,是对页面部分的渲染,以前PartialView的功能,可以使用 ...

  4. Hibernate入门详解

    学习Hibernate ,我们首先要知道为什么要学习它?它有什么好处?也就是我们为什么要学习框架技术? 还要知道    什么是Hibernate?    为什么要使用Hibernate?    Hib ...

  5. 修改nginx配置文件解决dx2.5下载附件停止不动的问题

    在下载论坛附件的时候,总是停止在某个字数数不动 如下图 后来查看log发现 如下图 权限拒绝 发现后nginx的配置文件的启动者有关系 改了下 user 为 root 居然好了

  6. VBA 格式化字符串 - Format大全

    VBA 格式化字符串 VBA 的 Format 函数与工作表函数 TEXT 用法基本相同,但功能更加强大,许多格式只能用于VBA 的 Format 函数,而不能用于工作表函数 TEXT ,以下是本人归 ...

  7. android 帧动画,补间动画,属性动画的简单总结

      帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...

  8. CALayer的m34 - 三维透视效果

    CATransform3D transform = CATransform3DIdentity; // 修改transform的m34达到透视效果 // - 1.0 / (500 ~ 1000 效果最 ...

  9. Cocos2dx中线程优先级

    Cocos2dx中线程优先级问题 不论是ios还是android,遇到耗时的任务都要另起线程处理,否则程序不能及时用户的反馈.游戏中如果一圈循环不能在1/frameRate(帧率是30则1/30)秒内 ...

  10. PullToRefreshListView的使用