HDOJ 2147 HDU 2147 kiki's game ACM 2147 IN HDU
题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=2147
题目描述:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/1000 K (Java/Others)
Total Submission(s): 1806 Accepted Submission(s): 1055
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!
题目分析:
分析如下:
P点:就是P个石子的时候,对方拿可以赢(自己输的)
N点:就是N个石子的时候,自己拿可以赢
现在关于P,N的求解有三个规则
(1):最终态都是P
(2):按照游戏规则,到达当前态的前态都是N的话,当前态是P
(3):按照游戏规则,到达当前态的前态至少有一个P的话,当前态是N
题意:
在一个m*n的棋盘内,从(1,m)点出发,每次可以进行的移动是:左移一,下移一,左下移一。然后kiki每次先走,判断kiki时候会赢(对方无路可走的时候)。
我们可以把PN状态的点描绘出来::
这些点的描绘有一个程序::
【
#include<iostream>
using namespace std;
bool map[2001][2001];//1 P 0 N;
int main(){
int i,j,k;
map[1][1]=1;
for(i=2;i<=2000;i++)
{
if(map[i-1][1])
map[i][1]=0;
else map[i][1]=1;
for(j=2;j<i;j++){
if(!map[i][j-1]&&!map[i-1][j-1]&&!map[i-1][j])
map[i][j]=1;
else map[i][j]=0;
}
if(map[1][i-1])
map[1][i]=0;
else map[1][i]=1;
for(j=2;j<i;j++){
if(!map[j-1][i]&&!map[j-1][i-1]&&!map[j][i-1])
map[j][i]=1;
else map[j][i]=0;
}
if(!map[i][i-1]&&!map[i-1][i-1]&&!map[i-1][i])
map[i][i]=1;
else map[i][i]=0;
}
int M,N;
for(i=1;i<=10;i++){
for(j=1;j<=10;j++)
printf("%c ",map[i][j]?'P':'N');
printf("\n");
}
while(scanf("%d%d",&M,&N)&&M&&N){
if(map[M][N]) printf("What a pity!\n");
else printf("Wonderful!\n");
}
return 0;
}
】
具体代码如下:
using namespace std;
int main ()
{
int n,m;
while ( cin >> n >> m , n + m )
{
puts ( n%2 && m % 2 ? "What a pity!" : "Wonderful!");
}
return 0;
}
转载于:https://www.cnblogs.com/MiYu/archive/2010/08/18/1802685.html
HDOJ 2147 HDU 2147 kiki's game ACM 2147 IN HDU相关推荐
- HDOJ 1874 HDU 1874 畅通工程续 ACM 1874 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1874 ...
- HDOJ 1213 HDU 1213 How Many Tables ACM 1213 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1213 ...
- HDOJ 1016 HDU 1016 Prime Ring Problem ACM 1016 IN HDU
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1016 题目描述: Prime Ring Problem Time Limit: 4000/2000 ...
- HDOJ 1253 HDU 1253 胜利大逃亡 ACM 1253 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1253 题目描述: ...
- HDOJ HDU 2058 The sum problem ACM 2058 IN HDU
//MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 : http://acm.hdu.edu.cn/showproblem.php?pid=2 ...
- HDOJ 1247 HDU 1247 Hat’s Words ACM 1247 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 : http://acm.hdu.edu.cn/showproblem.php?pid=1247 题目描述: ...
- HDOJ 1875 HDU 1875 畅通工程再续 ACM 1875 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1875 ...
- HDOJ 1286 HDU 1286 找新朋友 ACM 1286 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目描述: http://acm.hdu.edu.cn/showproblem.php?pid=1286 ...
- HDOJ HDU 1849 Rabbit and Grass ACM 1849 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1849 ...
- HDOJ HDU 2088 Box of Bricks ACM 2088 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=2088 ...
最新文章
- C++ 笔记(17)— 类和对象(构造函数、析构函数、拷贝构造函数)
- 基于python的移动物体检测_感兴趣区域的移动物体检测,框出移动物体的轮廓 (固定摄像头, opencv-python)...
- 中小型互联网公司微服务实践-经验和教训
- 【无码专区8】三角形二维数点——计数有多少个给定点落在三角形区域内
- python解析response的json_从HTML responseTex解析JSON
- 云小课 | 网站接入WAF失败怎么办?看这里就够了
- Intel超线程技术 Hyper-Threading Technology (4) - 处理器资源与超线程(分区的资源/竞争共享的资源)
- 《Java编码指南:编写安全可靠程序的75条建议》—— 指南16:避免授予过多特权...
- MATLAB 读取文件及数据
- springmvc application/octet-stream 问题
- c语言数组用户注册登入管理系统_[内附完整源码和文档] 基于JAVA的干部档案管理系统...
- Kindle多看系统中字典
- 【转】深入浅出的讲解傅里叶变换(真正的通俗易懂)
- 手机二维码~~~ZXing简介
- 输入偏置电流时钟馈通
- 视频消重伪原创版 怎么修改视频的MD5值
- erp scm crm 3者之间的关系如何
- 某一个输入的位数不确定的正整数按照标准的三位分节格式输出
- python制作游戏引擎_python制作galgame引擎(三)
- 测试图片真假软件,你的照片PS了么?10秒鉴别妹纸图真假