题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=2147

Problem Description
Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes the checkerboard game.The size of the chesserboard is n*m.First of all, a coin is placed in the top right corner(1,m). Each time one people can move the coin into the left, the underneath or the left-underneath blank space.The person who can't make a move will lose the game. kiki plays it with ZZ.The game always starts with kiki. If both play perfectly, who will win the game?
Input
Input contains multiple test cases. Each line contains two integer n, m (0<n,m<=2000). The input is terminated when n=0 and m=0.
Output
If kiki wins the game printf "Wonderful!", else "What a pity!".
Sample Input
5 3
5 4
6 6
0 0
Sample Output
What a pity!
Wonderful!
Wonderful!
 
启发博客:http://blog.csdn.net/liwen_7/article/details/7940164
反正思路就是找必胜点和必败点。博弈入门题。

必胜点(N点):当前位置走过去他要输了哈哈哈

必败点(P点):当前位置没的走了我要输了

所以

能走到必败点的都是必胜点

我们可以确定最后一个必败的情况(即物品数目为0,此题是指点(n,1)的位置,三个方向都找不到空位),然后反着推。可以找到规律:

     即:  当m为偶数 或  m为奇数且n为偶数的矩阵,先移硬币的人一定可以找到一个必败点,即先移的人一定最后可以到达(n,1)

当m、n均为奇数时,先移动的只能到达必胜点(即下一个选手取胜)。

 #include<cstdio>
#include<iostream>
using namespace std; int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF&&(n+m))
{
if((n%!=)&&(m%!=))
printf("What a pity!\n");
else
printf("Wonderful!\n");
}
return ;
}

HDU 2147 kiki's game(博弈经典题)的更多相关文章

  1. HDU 2147 kiki's game(博弈图上找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2147 题目大意:给你一个n*m的棋盘,初始位置为(1,m),两人轮流操作,每次只能向下,左,左下这三个 ...

  2. HDU 2147 kiki's game(博弈)

    kiki's game Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Submit S ...

  3. hdu 2147 kiki&#39;s game, 入门基础博弈

    博弈的一些概念: 必败点(P点) : 前一个选手(Previous player)将取胜的位置称为必败点. 必胜点(N点) : 下一个选手(Next player)将取胜的位置称为必胜点. 必败(必胜 ...

  4. HDU.2147 kiki's game (博弈论 PN分析)

    HDU.2147 kiki's game (博弈论 PN分析) 题意分析 简单的PN分析 博弈论快速入门 代码总览 #include <bits/stdc++.h> using names ...

  5. hdu 2147 kiki's game(巴什博弈)

    kiki's game HDU - 2147 题意:一个n*m的表格,起始位置为右上角,目标位置为左下角,甲先开始走,走的规则是可以向左,向下或者向左下(对顶的)走一格.谁先走到目标位置谁就胜利.在甲 ...

  6. hdu 1045:Fire Net(DFS经典题)

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  7. HDU 2147 kiki's game(规律,博弈)

    kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)Total ...

  8. HDU 2147 kiki's game (简单博弈,找规律)

    kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others)Total ...

  9. HDU - 2147 kiki's game 巴什博弈

    思路:以终点(n, m)作为P态,倒推各个坐标的状态,最终得到结论:行数或列数是偶数就能赢,否则输.        AC代码 #include <cstdio> #include < ...

随机推荐

  1. 1013. Pairs of Songs With Total Durations Divisible by 60总持续时间可被 60 整除的歌曲

    网址:https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/submissions/ 参考 ...

  2. Intersecting Lines

    Intersecting Lines We all know that a pair of distinct points on a plane defines a line and that a p ...

  3. 【转】在使用实体框架(Entity Framework)的应用中加入审计信息(Audit trail)跟踪数据的变动

    在一些比较重要的业务系统中,通常会要求系统跟踪数据记录的变动情况.系统要记录什么时间,什么人,对那些信息进行了变动. 比较简单的实现方式是在每个表中加入两个字段CreatedBy和CreatedAt, ...

  4. 蓝桥杯—BASIC-25 回形取数

    题目:回形取数就是沿矩阵的边取数,若当前方向上无数可取或已经取过,则左转90度.一开始位于矩阵左上角,方向向下.输入格式 输入第一行是两个不超过200的正整数m, n,表示矩阵的行和列.接下来m行每行 ...

  5. 1-3Controller之Response

    控制器中的方法: public function response1(){ /*响应的常见类型: * 1.字符串 * 2.视图 * 3.json * 4.重定向 * */ //响应JSON /*$da ...

  6. learning hdmi edid protocol

    referenc: https://en.wikipedia.org/wiki/Extended_Display_Identification_Data

  7. flask+apache+mod-wsgi部署遇到的坑

    首先,看到这种方式部署,我也有疑问,为什么不用nginx,gunicorn.接手的项目,就先按照前人思路run起来. 线上使用ubuntu系统,apache2,而给我玩耍的测试机是centos6.5, ...

  8. Java反射《三》获取属性

    package com.study.reflect; import java.lang.reflect.Field; /** * 反射,获取属性 * @ClassName: FieldDemo * @ ...

  9. ural1517

    题解: 后缀数组 求一下最长公共字串 代码: #include<cstdio> #include<cmath> #include<algorithm> #inclu ...

  10. day14-python异常处理

    1.     异常 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在Python无法正常处理程序时就会发生一个异常.异常是Python对象,表示一个错误.当Pyt ...