HDU 2147 kiki's game(博弈)
2016-06-29 13:09
330 查看
kiki's game
Submit Status
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!
题意:有一个N*M的棋盘,硬币在(1,M),两个人轮流移动,每次可以将硬币向左或向下或向左下移动。
谁不能继续移动了谁输,赢了输出Wonderful!,输了输出What a pity!。
题解:左下角肯定是必败点P了,他的上,右和右上是必胜点N,依次递推可以得出:
PNPNPNPNP
NNNNNNNNN
PNPNPNPNP
NNNNNNNNN
PNPNPNPNP
NNNNNNNNN
PNPNPNPNP
即如果n和m都是奇数则为必败点,否则为必胜点。
注意:本题也叫“分”数问题,给定两个数每次将一个数变为0,另一个数分成两份给这两个数。
结论与本题一样,都是奇数则必败,根据(1,1)是P然后逆向递推即可得出结论。
顺便说一下另一种博弈:Chomp!博弈,即拿巧克力问题。结论:除了(1,1)都是必胜点。很好证明:
如果后手能赢,也就是说后手有必胜策略,使得无论先手第一次取哪个石子,后手都能获得最后的胜利。
那么现在假设先手取最右上角的石子(n,m),接下来后手通过某种取法使得自己进入必胜的局面。
但事实上,先手在第一次取的时候就可以和后手这次取的一样,进入必胜局面了,与假设矛盾。
以下是本题AC代码:
Time Limit: 1000MS | Memory Limit: 10000KB | 64bit IO Format: %I64d & %I64u |
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!
题意:有一个N*M的棋盘,硬币在(1,M),两个人轮流移动,每次可以将硬币向左或向下或向左下移动。
谁不能继续移动了谁输,赢了输出Wonderful!,输了输出What a pity!。
题解:左下角肯定是必败点P了,他的上,右和右上是必胜点N,依次递推可以得出:
PNPNPNPNP
NNNNNNNNN
PNPNPNPNP
NNNNNNNNN
PNPNPNPNP
NNNNNNNNN
PNPNPNPNP
即如果n和m都是奇数则为必败点,否则为必胜点。
注意:本题也叫“分”数问题,给定两个数每次将一个数变为0,另一个数分成两份给这两个数。
结论与本题一样,都是奇数则必败,根据(1,1)是P然后逆向递推即可得出结论。
顺便说一下另一种博弈:Chomp!博弈,即拿巧克力问题。结论:除了(1,1)都是必胜点。很好证明:
如果后手能赢,也就是说后手有必胜策略,使得无论先手第一次取哪个石子,后手都能获得最后的胜利。
那么现在假设先手取最右上角的石子(n,m),接下来后手通过某种取法使得自己进入必胜的局面。
但事实上,先手在第一次取的时候就可以和后手这次取的一样,进入必胜局面了,与假设矛盾。
以下是本题AC代码:
#include<iostream> #include<cstdio> using namespace std; int main() { int n,m; while(cin>>n>>m&&n&&m) { if(n&1&&m&1) puts("What a pity!"); else puts("Wonderful!"); } return 0; }
相关文章推荐
- Gradle构建系统简介及在Gradle中集成覆盖率工具Jacoco并使用
- I.MX6 wpa_cli 使用
- Java定时器的使用(Timer)
- 去掉tomcat项目访问路径的端口号和项目名
- LSD快速直线检测的原理概要及OpenCV代码实现(CV类LineSegmentDetector)
- cocos2d WebSocket简单例子
- zookeeper的安装
- Spark mllib 随机森林算法的简单应用(附代码)
- zookeeper的安装
- android 如何将图片转化成字符串
- 5中水平垂直居中方法
- 分享一个技术网站-猿天地-cxytiandi.com
- 代码注释规范-google版本
- python2.0_s12_day11_SqlAlchemy使用介绍
- lua 判断颜色相似
- android:gravity 和 android:layout_Gravity的区别
- Win7基于theano的keras安装及GPU加速
- CCNA基础知识摘录
- Python模块之Logging(五)——在配置文件中为Logger配置多个handler
- poj 2078 Matrix