• hdu 2149+hdu 1846(巴什博弈)


    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2149

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

    分析:显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜。因此我们发现了如何取胜的法则:如果n=m+1r+s,(r为任意自然数,sm),那么先取者要拿走s个物品,如果后取者拿走km)个,那么先取者再拿走m+1-k个,结果剩下(m+1)(r-1)个,以后保持这样的取法,那么先取者肯定获胜。总之,要保持给对手留下(m+1)的倍数,就能最后获胜。

    View Code
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 using namespace std;
     6 
     7 int main(){
     8     int n,m;
     9     while(~scanf("%d%d",&m,&n)){
    10         if(m%(n+1)==0){puts("none");continue;}
    11         else {
    12             if(m<=n){
    13                 printf("%d",m);
    14                 for(int i=m+1;i<=n;i++)printf(" %d",i);
    15                 puts("");
    16             }else {
    17                 printf("%d\n",m%(n+1));
    18             }
    19         }
    20     }
    21     return 0;
    22 }

     题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1846

    View Code
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 int main(){
     7     int _case,n,m;
     8     scanf("%d",&_case);
     9     while(_case--){
    10         scanf("%d%d",&n,&m);
    11         if(n%(m+1)==0)puts("second");
    12         else puts("first");
    13     }
    14     return 0;
    15 }
  • 相关阅读:
    thinkphp 5 隐藏index.php
    jquery ajax参数
    图标字的使用方法
    jquery监听浏览宽度
    手机屏幕的宽度自动适应
    前站常用代码
    服务消费者(Feign-上)
    服务消费者(Ribbon)
    注册中心(Eureka/Consul)
    JDK8 日期格式化
  • 原文地址:https://www.cnblogs.com/wally/p/3065985.html
Copyright © 2020-2023  润新知