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 ...
随机推荐
- centos7 上搭建私有云
OwnCloud环境搭建 一. 环境搭建 1. 环境需求 服务器操作系统:Centos7.0 外网服务器操作系统:Centos7.0 Php版本号:5.4.16 Mysql版本号:5.5.52 Apa ...
- sqlservr.exe占用大量内存
SQL Server是如何使用内存 最大的开销一般是用于数据缓存,如果内存足够,它会把用过的数据和觉得你会用到的数据统统扔到内存中,直到内存不足的时候,才把命中率低的数据给清掉.所以一般我们在看sta ...
- kill、PKill、xkill 和killall----杀死进程
终止一个进程或终止一个正在运行的程序,一般是通过kill .killall.pkill.xkill 等进行.比如一个程序已经死掉,但又不能退出,这时就应该考虑应用这些工具.另外应用的场合就是在服务器管 ...
- LCD控制器与帧率、刷新率的关系分析
源:LCD控制器与帧率.刷新率的关系分析 LCM之Fmark功能 && LCD控制器同LCD驱动器的差别 && 帧率与刷新率的关系 && OLED背光
- jQuery焦点图插件
在线演示 本地下载
- GitLab 安装与入门
GitLab介绍: GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. GitLab拥有与Github ...
- struts2——文件下载自定义文件名,包括中文
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- mysql 创建数据库 并设置utf8格式
CREATE DATABASE `database` CHARACTER SET utf8 COLLATE utf8_general_ci; 设置utf8之后,不容易出现中文乱码.
- Dynamo论文介绍
http://catkang.github.io/2016/05/27/dynamo.html Dynamo是Amazon开发的分布式存储系统,本文是阅读Dynamo论文后的总结:Dynamo: Am ...
- 10 个深恶痛绝的 Java 异常
异常是 Java 程序中经常遇到的问题,我想每一个 Java 程序员都讨厌异常,一 个异常就是一个 BUG,就要花很多时间来定位异常问题. 今天,来列一下 Java 中经常遇到的前 10 个异常,排名 ...