CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)
As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initially contains ai stones. Two players alternate the turns. During a turn a player picks any non-empty pile and removes any positive number of stones from it. The one who is not able to make a move loses the game.
Petya and Vasya are tired of playing Nim, so they invented their own version of the game and named it the "Gambling Nim". They have n two-sided cards, one side of the i-th card has number ai written on it, while the other side has number bi. At the beginning of the game the players put all the cards on the table, each card only one of its sides up, and this side is chosen independently and uniformly. Thus they obtain a sequence c1, c2, ..., cn, where ci is equal to ai or bi. Then they take n piles of stones, with i-th pile containing exactly ci stones and play Nim. Petya takes the first turn.
Given that both players play optimally, find the probability of Petya's victory. Output the answer as an irreducible fraction.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of cards in the deck.
Each of the following n lines contains the description of one card, consisting of two integers ai and bi (0 ≤ ai, bi ≤ 1018).
Output
Output the answer as an irreducible fraction p / q. If the probability of Petya's victory is 0, print 0/1.
Examples
2
1 1
1 1
0/1
2
1 2
1 2
1/2
3
0 4
1 5
2 3
1/1
(占位,还是没有搞懂)
有点像线性基,但是这个是不去重的,而且用的是lowbit~~~晕啦。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = ;
ll a[maxn],b[maxn],c[],cnt;
#define lowbit(x) (x&-x)
int main(){
ll n,S=;scanf("%I64d",&n);
for(int i=;i<=n;++i){
scanf("%I64d%I64d",&a[i],&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("%I64d/%I64d\n",x-,x);
}
getchar();getchar();
return ;
}
CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)的更多相关文章
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- 【题解】 Codeforces 662A Gambling Nim (线性基)
662A,戳我戳我 Solution: 我们先取\(ans=a[1] \bigoplus a[2] \bigoplus ... \bigoplus a[n]\),然后我们定义\(c[i]=a[i] \ ...
- 【CF662A】Gambling Nim 线性基
[CF662A]Gambling Nim 题意:n长卡牌,第i张卡牌正面的数字是$a_i$,反面的数字是$b_i$,每张卡牌等概率为正面朝上或反面朝上.现在Alice和Bob要用每张卡牌朝上的数字玩N ...
- hdu6055 Regular polygon 脑洞几何 给定n个坐标(x,y)。x,y都是整数,求有多少个正多边形。因为点都是整数点,所以只可能是正四边形。
/** 题目:hdu6055 Regular polygon 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6055 题意:给定n个坐标(x,y).x,y都 ...
- HDOJ-2222(AC自动机+求有多少个模板串出现在文本串中)
Keywords Search HDOJ-2222 本文是AC自动机的模板题,主要是利用自动机求有多少个模板出现在文本串中 由于有多组输入,所以每组开始的时候需要正确的初始化,为了不出错 由于题目的要 ...
- 算法进阶面试题07——求子数组的最大异或和(前缀树)、换钱的方法数(递归改dp最全套路解说)、纸牌博弈、机器人行走问题
主要讲第五课的内容前缀树应用和第六课内容暴力递归改动态规划的最全步骤 第一题 给定一个数组,求子数组的最大异或和. 一个数组的异或和为,数组中所有的数异或起来的结果. 简单的前缀树应用 暴力方法: 先 ...
- Codeforces Round #340 (Div. 2) E 莫队+前缀异或和
E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- codeforces 15C. Industrial Nim
题目链接:http://codeforces.com/problemset/problem/15/C $NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多. 考虑利用异或的性 ...
- HDU 1729 类NIM 求SG
每次有n个盒子,每个盒子有容量上限,每次操作可以放入石头,数量为不超过当前盒子中数量的平方,不能操作者输. 一个盒子算一个子游戏. 对于一个盒子其容量为s,当前石子数为x,那么如果有a满足 $a \t ...
随机推荐
- nodejs两个例子
1.nodejs多线程 var cluster=require("cluster");//ͨ¹ýcluster¿ÉÒÔ·Ö³öһЩ×ÓÏß³Ì var http=requir ...
- JetBrains IntelliJ IDEA 15 Ultimate Edition版本激活破解
由于JetBrains系列新版本注册激活发生了变化,所以原来的激活方式已经不能在使用. 只能用新的方式来破解了.此方式支持所有系列的新版版.包括IDEA15,PHPSTORM10,WEBSTO ...
- javascript 中的比较大小,兼 typeof()用法
javascript中的排序: 1.不同类型 比 类型 (字符串 > 数字) 2.同类型:(字符串 比 按字母顺序 )(数字 比 大小) 测试: <!DOCTYPE html> ...
- 自定义Checkbox和Radiobox
在线演示 本地下载
- Maven:如何在eclipse里新建一个Maven的java项目和web项目
如何在eclipse里新建一个Maven的java项目和web项目: 一:java项目 New-->Other-->Maven 右击项目-->properties,修改以下文件: ① ...
- React Native实战系列教程之自定义原生UI组件和VideoView视频播放器开发
React Native实战系列教程之自定义原生UI组件和VideoView视频播放器开发 2016/09/23 | React Native技术文章 | Sky丶清| 4 条评论 | 1 ...
- Spring AOP(4)
- UVA 725 UVA 10976 简单枚举
UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...
- Autofac is designed to track and dispose of resources for you.
https://autofaccn.readthedocs.io/en/latest/best-practices/ Autofac is designed to track and dispose ...
- Logstash过滤器修改数据
数据修改(Mutate) filters/mutate 插件是 Logstash 另一个重要插件.它提供了丰富的基础类型数据处理能力.包括类型转换,字符串处理和字段处理等. 类型转换 类型转换是 fi ...