题目传送: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. sqlserver创建计算列 转

    转 http://www.cnblogs.com/lgx5/p/6017874.html 表中其它列的计算值 创建的sql create table table1 ( number decimal(1 ...

  2. PAT 1046 Shortest Distance

    1046 Shortest Distance (20 分)   The task is really simple: given N exits on a highway which forms a ...

  3. 函数使用五:MIR7 发票预制 BAPI_INCOMINGINVOICE_PARK

    引自:http://blog.csdn.net/champaignwolf/article/details/51422329 FUNCTION zincominginvoice_park. *&quo ...

  4. Linux下切换使用两个版本的JDK

    Linux下切换使用两个版本的JDK 我这里原来已经配置好过一个1.7版本的jdk. 输出命令: java -version [root@hu-hadoop1 sbin]# java -version ...

  5. Jenkins的安装、启动和配置

    一.Jenkins的安装 1.前提条件:已经成功安装了JDK,因为jenkins是一款基于Java的持续集成工具. 2.准备工具:下载一个jenkins的war包. 3.启动方法:如把jenkins. ...

  6. learning svn change commit log

    将repository内hook子文件夹中的pre-revprop-change.tmpl复制改成pre-revprop-change.bat,内容改为:exit 0

  7. bzoj3879

    题解: 后缀数组 然后把读入的内容去重,按照rank排序 然后用单调栈处理一下 代码: #include<bits/stdc++.h> using namespace std; typed ...

  8. nginx+tomcat集群

    参考: 简单:http://blog.csdn.net/wang379275614/article/details/47778201 详细:http://www.jb51.net/article/77 ...

  9. python 爬虫之 selenium API

    一.浏览器操作 1.浏览器最大化 driver.maximize_window() #将浏览器最大化显示 2.设置浏览器宽.高 driver.set_window_size(480, 800)#设置浏 ...

  10. TCP/IP协议 计算机间的通讯,传输、socket 传输通道

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- #TCP/IP简介 #为了把全世界的所有不同类型的计算机都连接起来,就必须规定一套全球通用的协议,为了实现 ...