zoukankan      html  css  js  c++  java
  • 四种基本组合博弈POJ1067/HDU1846

    取石子游戏
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 43466   Accepted: 14760

    Description

    有 两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆 中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是 败者。

    Input

    输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大于1,000,000,000。

    Output

    输出对应也有若干行,每行包含一个数字1或0,如果最后你是胜者,则为1,反之,则为0。

    Sample Input

    2 1
    8 4
    4 7

    Sample Output

    0
    1
    0

    Source

     

    威佐夫博弈(Wythoff's Game)

    结论:设a < b,若a = [((√5 + 1)/2 * (b - a))],则为必败局面,否则为必胜局面

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <queue>
     7 #include <vector>
     8 #include <cmath> 
     9 #define min(a, b) ((a) < (b) ? (a) : (b))
    10 #define max(a, b) ((a) > (b) ? (a) : (b))
    11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
    12 inline void swap(int &a, int &b)
    13 {
    14     int tmp = a;a = b;b = tmp;
    15 }
    16 inline void read(int &x)
    17 {
    18     x = 0;char ch = getchar(), c = ch;
    19     while(ch < '0' || ch > '9') c = ch, ch = getchar();
    20     while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    21     if(c == '-') x = -x;
    22 }
    23 
    24 const int INF = 0x3f3f3f3f;
    25 
    26 int a,b;
    27 
    28 int main()
    29 {
    30     while(scanf("%d %d", &a, &b) != EOF)
    31     {
    32         if(a > b) swap(a, b);
    33         if((int)(((sqrt(5) + 1.0)/2) * (b - a)) == a) printf("0
    ");
    34         else printf("1
    ");
    35     }
    36     return 0;
    37 } 
    POJ1067

     

    Brave Game

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 13313    Accepted Submission(s): 8997


    Problem Description
    十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫《勇敢者的游戏》(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻。
    今天,大家选择上机考试,就是一种勇敢(brave)的选择;这个短学期,我们讲的是博弈(game)专题;所以,大家现在玩的也是“勇敢者的游戏”,这也是我命名这个题目的原因。
    当然,除了“勇敢”,我还希望看到“诚信”,无论考试成绩如何,希望看到的都是一个真实的结果,我也相信大家一定能做到的~

    各位勇敢者要玩的第一个游戏是什么呢?很简单,它是这样定义的:
    1、  本游戏是一个二人游戏;
    2、  有一堆石子一共有n个;
    3、  两人轮流进行;
    4、  每走一步可以取走1…m个石子;
    5、  最先取光石子的一方为胜;

    如果游戏的双方使用的都是最优策略,请输出哪个人能赢。
     

     

    Input
    输入数据首先包含一个正整数C(C<=100),表示有C组测试数据。
    每组测试数据占一行,包含两个整数n和m(1<=n,m<=1000),n和m的含义见题目描述。
     

     

    Output
    如果先走的人能赢,请输出“first”,否则请输出“second”,每个实例的输出占一行。
     

     

    Sample Input
    2 23 2 4 3
     

     

    Sample Output
    first second
     

     

    Author
    lcy
     

     

    Source
     

     

    Recommend
     
    巴什博奕(Bash Game)

    若局面为(m+1)x + r,先手取r,无论后手怎么取,先手总能取成(m+1)x的局面,等到了m + 1,后手最多取m,先手必胜

    若局面为(m+1)x,无论先手怎么取,后手总能取成(m+1)x的局面,同上理,后手必胜

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <queue>
     7 #include <vector>
     8 #include <cmath> 
     9 #define min(a, b) ((a) < (b) ? (a) : (b))
    10 #define max(a, b) ((a) > (b) ? (a) : (b))
    11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
    12 inline void swap(int &a, int &b)
    13 {
    14     int tmp = a;a = b;b = tmp;
    15 }
    16 inline void read(int &x)
    17 {
    18     x = 0;char ch = getchar(), c = ch;
    19     while(ch < '0' || ch > '9') c = ch, ch = getchar();
    20     while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
    21     if(c == '-') x = -x;
    22 }
    23 
    24 const int INF = 0x3f3f3f3f;
    25 
    26 int t,n,m;
    27 
    28 int main()
    29 {
    30     read(t);
    31     for(;t;--t)
    32     {
    33         read(n), read(m);
    34         if(n % (m + 1) == 0) printf("second
    ");
    35         else printf("first
    ");
    36     }
    37     return 0;
    38 } 
    HDU1846

     尼姆博弈(Nimm Game) 略

    斐波那契博弈(Fibonacci Game) 一堆物品,两人轮流去,第一个人不能把物品全取完,以后每个人可以去至少一个至多前面的人取的个数的两倍个

    结论:先手胜当且仅当n不是Fibnocci数

     

     

  • 相关阅读:
    SQLServerframework启动报异常:Module的类型初始值设定项引发异常
    在coding或者github建立个人站点域名绑定
    Github速度慢的解决方法
    jsoup爬取网站图片
    activeMQ类别和流程
    Session session = connection.createSession(paramA,paramB);参数解析
    Ehcache入门经典:第二篇ehcache.xml的参数
    Ehcache入门经典:第一篇
    处理高并发
    扩充次数和创建个数问题
  • 原文地址:https://www.cnblogs.com/huibixiaoxing/p/8308335.html
Copyright © 2011-2022 走看看