• hdu 3032 Nim or not Nim? 博弈论


     这题是Lasker’s Nim.

    Clearly the Sprague-Grundy function for the one-pile game satisfies g(0) = 0 and g(1) = 1. The followers of 2 are 0, 1 and (1,1), with respective Sprague-Grundy values of 0, 1, and 1⊕1 = 0. Hence, g(2) = 2. The followers of 3 are 0, 1, 2, and (1,2), with Sprague-Grundy values 0, 1, 2, and 1⊕2 = 3. Hence, g(3) = 4.

    Continuing in this manner, we see

    x 0 1 2 3 4 5 6 7 8 9 10 11 12...

    g(x) 0 1 2 4 3 5 6 8 7 9 10 12 11...

    We therefore conjecture that g(4k + 1) = 4k + 1,g(4k + 2) = 4k + 2,g(4k + 3) = 4k +4 and g(4k + 4) = 4k + 3, for all k ≥ 0.

    代码如下:

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<algorithm>
     4 #include<iomanip>
     5 #include<cmath>
     6 #define in(x) scanf("%d",&x)
     7 using namespace std;
     8 int main(){
     9     int  n,t,ans,k;
    10     in(t);
    11     while(t--){
    12         in(n);
    13         ans=0;
    14         for(int i=0;i<n;i++){
    15             in(k);
    16             if(k%4==0) ans^=k-1;
    17             else if(k%4==3) ans^=k+1;
    18             else ans^=k;
    19         }
    20         puts(ans?"Alice":"Bob");
    21     }
    22     return 0;
    23 }
    View Code
  • 相关阅读:
    git命令
    WPF让绑定支持表达式
    WPF多语言动态切换的一种方法
    C#监测系统事件,睡眠状态
    记一次渗透测试
    Relay
    ECShop相关漏洞复现/分析
    人工智能学习路线图
    抽奖算法
    关于微信开发的 appid,openid,unionid
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3256109.html
Copyright © 2020-2023  润新知