码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-10-01 21:41:53      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:int   efi   pen   def   alternate   pos   oba   typedef   ons   

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

Input
2
1 1
1 1
Output
0/1
Input
2
1 2
1 2
Output
1/2
Input
3
0 4
1 5
2 3
Output
1/1

 

(占位,还是没有搞懂)

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500010;
ll a[maxn],b[maxn],c[65],cnt;
#define lowbit(x) (x&-x)
int main(){
    ll n,S=0;scanf("%I64d",&n);
    for(int i=1;i<=n;++i){
        scanf("%I64d%I64d",&a[i],&b[i]);
        S^=a[i];a[i]^=b[i];
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=cnt;++j){
            if(a[i] & lowbit(c[j])) a[i] ^= c[j];
        }if(a[i] != 0) c[++cnt] = a[i];
    }
    for(int i=1;i<=cnt;++i){
        if(S & lowbit(c[i])) S ^= c[i];
    }
    if(S != 0) puts("1/1");
    else{
        ll x = 1LL<<cnt;
        printf("%I64d/%I64d\n",x-1,x);
    }
    getchar();getchar();
    return 0;
}

 

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

标签:int   efi   pen   def   alternate   pos   oba   typedef   ons   

原文地址:https://www.cnblogs.com/hua-dong/p/9735733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!