zoukankan      html  css  js  c++  java
  • 常用博弈模板(纯模板 利于记忆)

    1、巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规
    定每次至少取一个,最多取m个。最后取光者得胜。

    #include<iostream>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    const int N=1e6+50;
    const int INF=0x3f3f3f3f;
    typedef long long ll;
    int main()
    {
        int n,a,b;
        while(~scanf("%d%d%d",&n,&a,&b))
        {
            int sum=n%(a+b);
            if(sum==0)
                printf("WIN
    ");
            else if(sum<=a)
                printf("LOST
    ");
            else
                printf("WIN
    ");
        }
       return 0;
    }
    

    2、威佐夫博奕(Wythoff Game):有两堆各若干个物品,两个人轮流从某一堆取任意数量或同
    时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜。

    #include<iostream>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    const int N=2e5+50;
    const int INF=0x3f3f3f3f;
    typedef long long ll;
    int a[N];
    int main()
    {
        int n,m;
        while(~scanf("%d%d",&n,&m))
        {
            if(n<m)
            {
               swap(n,m);
            }
            int k=n-m;
            n=(int)(k*(1+sqrt(5.0))/2);
            if(n==m)
                printf("0
    ");//输
            else
              printf("1
    ");//赢
        }
        return 0;
    }
    

    3、尼姆博奕(Nimm Game):有三堆各若干个物品,两个人轮流从某一堆取任意多的
    物品,规定每次至少取一个,多者不限,最后取光者得胜。

    #include<iostream>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    const int N=2e5+50;
    const int INF=0x3f3f3f3f;
    typedef long long ll;
    int a[N];
    int main()
    {
       int n;
       while(scanf("%d",&n))
       {
           if(n==0)
            break;
            int sg=0;
           for(int i=0;i<n;i++)
           {
               scanf("%d",a+i);
               sg^=a[i];
           }
           if(sg==0)
            printf("No
    ");
           else
           {
               printf("Yes
    ");
           }
       }
       return 0;
    }
    

      

  • 相关阅读:
    zabbix自定义监控mysql
    [学习笔记]动态树Link-Cut-Tree
    关于 /etc/zabbix/zabbix_agentd.conf 文件 Hostname 文件的说明
    NOIP2018 游记
    Centos7安装Zabbix3.4
    [学习笔记]动态dp
    Java实现 泊松分酒
    关于使用索引的一些经验
    OI生涯回忆录 2017.9.10~2018.11.11
    覆盖索引小结
  • 原文地址:https://www.cnblogs.com/alpacadh/p/9114216.html
Copyright © 2011-2022 走看看