题目传送: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 ;
}

最新文章

  1. VS低版本打开高版本解决方案(如08打开10、12、13版本vs编译的项目)
  2. Hadoop学习笔记—18.Sqoop框架学习
  3. 安装CentOS、Linux系统时,GPT分区不能引导的解决方法
  4. 分布式集群搭建(hadoop2.6.0+CentOS6.5)
  5. 【Algorithm】堆排,C++实现
  6. Build A Micro Team
  7. Redis一些命令总结
  8. oc之封装与类之间的关系
  9. 找斐波那契数列中的第N个数——递归与函数自调用算法
  10. js判断语句关于true和false后面跟数字或字符串的问题
  11. 高通平台获取secure boot,串号等状态
  12. PHP文件系统管理
  13. ibevent 和 libev 提高网络应用性能【转】
  14. Spring Boot参数校验
  15. Spring容器的创建刷新过程
  16. TypeError: view must be a callable or a list/tuple in the case of include()
  17. log4j2笔记 #04# Appender的三个基本款以及RollingFile的各种示例配置
  18. C++手机通讯录排序
  19. 零基础学习python_生成器(49课)
  20. linux 查看版本

热门文章

  1. C++的字符串多行输入
  2. MIR7预制发票扣除已经预制的数量(每月多次预制,未即时过账)
  3. python中RabbitMQ的使用(远程过程调用RPC)
  4. Git中ssh的使用
  5. 【LeetCode】Valid Parentheses合法括号
  6. 如何解决Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a. 问题
  7. loj 10117 简单题(cqoi 2006)
  8. Oracle12c版本中未归档隐藏参数
  9. Physical&#160;Limits&#160;of&#160;ASM
  10. Linux tar压缩命令 排除某个目录 (根据man tar 总结)