zoukankan      html  css  js  c++  java
  • CodeForces

    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

    (占位,还是没有搞懂)

     有点像线性基,但是这个是不去重的,而且用的是lowbit~~~晕啦。

    #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
    ",x-1,x);
        }
        getchar();getchar();
        return 0;
    }
  • 相关阅读:
    asp.net在线压缩和解压缩的实现 VS2005
    Office组件配置
    您无权查看或编辑目前 F:\XXX 的权限设置;但是,您可以取得所有权或更改审核设置
    23条心灵寄语献给在创业一线的兄弟姐妹
    IIS 环境下 w3wp.exe 进程 CPU 占用过高的解决方案
    SQLServer修改表所有者
    走出软件作坊推荐
    Asp.net 的 服务器推技术 (Server Push)
    上海火车站售票点
    Newtonsoft.Json.dll 本地调用正常,服务器调用不正常
  • 原文地址:https://www.cnblogs.com/hua-dong/p/9735733.html
Copyright © 2011-2022 走看看