• 常用博弈模板(纯模板 利于记忆)


    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;
    }
    

      

  • 相关阅读:
    浏览器基础知识点及常考面试题
    java设计模式之综述
    maven的基本原理和使用
    maven的介绍和安装
    Spring整合Struts2的方法
    Spring整合Hibernate的方法
    Spring中的事务管理
    Spring中的JDBC操作
    基于XML配置的Sping AOP详解
    基于注解的Sping AOP详解
  • 原文地址:https://www.cnblogs.com/alpacadh/p/9114216.html
Copyright © 2020-2023  润新知