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;
    }
  • 相关阅读:
    KUDU 介绍
    Redis是什么?什么作用?优点和缺点
    数据库的种类有哪些?
    oracle 存储过程之游标(loop)使用
    JsHelper.cs
    MsSqlHelper.cs
    PLSQL操作Oracle创建用户和表(含创建用户名和密码)
    ASP.NET开发--三层架构
    oracle数据库之数据插入、修改和删除
    IDEA 搭建SSM框架详细教程以及token本地运行环境常遇到的问题
  • 原文地址:https://www.cnblogs.com/hua-dong/p/9735733.html
Copyright © 2011-2022 走看看