zoukankan      html  css  js  c++  java
  • [2016北京集训试题6]魔法游戏-[博弈论-sg函数]

    Description

    Solution

    首先,每个节点上的权值可以等价于该节点上有(它的权的二进制位数+1)个石子,每次可以拿若干个石子但不能不拿。

    然后就发现这和NIM游戏很像,就计算sg函数em(然而我并不会推)

    如果您恰好看到这篇博,又恰好有空的话,欢迎探讨~

    Code

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    using namespace std;
    typedef unsigned long long ull;
    int n,x,y;
    int num[100010];
    ull t;
    struct G{int y,nxt;}g[200010];int h[100010],tot=0;
    int dfs(int x,int fa)
    {
        int c=num[x],d=0;
        for (int i=h[x];i;i=g[i].nxt)
            if (g[i].y!=fa) d^=dfs(g[i].y,x);
        return c-=(c<=d);
    }
    int main()
    {
        while (scanf("%d",&n)!=EOF)
        {
            for (int i=1;i<=n;i++){scanf("%llu",&t);num[i]=(int)log2(t)+1;}
            memset(h,0,sizeof(h));tot=0;
            for (int i=1;i<n;i++)
            {
                scanf("%d%d",&x,&y);x++;y++;
                g[++tot]=G{y,h[x]};h[x]=tot;
                g[++tot]=G{x,h[y]};h[y]=tot;
            }
            dfs(1,0)?printf("Alice
    "):printf("Marisa
    ");      
        }
    }
  • 相关阅读:
    变量的使用
    Matrix Operations
    Modify tensor shape
    张量的创建
    feed_dict 的使用
    安装并配置 HBase2.2.2
    HDFS 编程实践(Hadoop3.1.3)
    TensorFlow的安装
    GUI tkinter (Menu) -弹出菜单
    GUI tkinter (Menu) -下拉菜单
  • 原文地址:https://www.cnblogs.com/coco-night/p/9690925.html
Copyright © 2011-2022 走看看