HDOJ 2147 HDU 2147 kiki's game ACM 2147 IN HDU
2010-08-18 17:47
477 查看
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋
题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=2147
题目描述:
kiki's game
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!
题目分析:
一直WA , 分析也没分析出来 , 百度了一下别人的解题报告后.............我承认....我被征服了.....................
分析如下:
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]
) printf("What a pity!\n");
else printf("Wonderful!\n");
}
return 0;
}
】
具体代码如下:
#include <iostream>
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;
}
题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=2147
题目描述:
kiki's game
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!
题目分析:
一直WA , 分析也没分析出来 , 百度了一下别人的解题报告后.............我承认....我被征服了.....................
分析如下:
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]
) printf("What a pity!\n");
else printf("Wonderful!\n");
}
return 0;
}
】
具体代码如下:
#include <iostream>
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;
}
相关文章推荐
- HDOJ HDU 2061 Treasure the new start, freshmen! ACM 2061 IN HDU
- HDOJ 1215 HDU 1215 七夕节 ACM 1215 IN HDU
- HDOJ 2526 HDU 2526 浪漫手机 ACM 2526 IN HDU
- HDU 2246 HDOJ 2246 考研路茫茫——考试大纲 ACM 2246 IN HDU
- HDU 3468 HDOJ 3468 A Simple Problem with Integers ACM 3468 IN HDU
- HDOJ HDU 1982 Kaitou Kid - The Phantom Thief(1) ACM 1982 IN HDU
- HDOJ HDU 1060 Leftmost Digit ACM 1060 IN HDU
- HDOJ 1406 HDU 1406 完数 ACM 1406 IN HDU
- HDU 2795 HDOJ 2795 Billboard ACM 2795 IN HDU
- HDOJ HDU 2673 shǎ崽 OrOrOrOrz ACM 2673 IN HDU
- HDOJ HDU 1023 1130 1133 1134 2067 ACM 1023 1130 1133 1134 2067 IN HDU ( 卡特兰数 专题 catalan )
- HDOJ HDU 2149 Public Sale ACM 2149 IN HDU
- HDOJ HDU 2068 RPG的错排 ACM 2068 IN HDU
- HDOJ HDU 1133 Buy the Ticket ACM 1133 IN HDU
- HDOJ 1286 HDU 1286 找新朋友 ACM 1286 IN HDU
- HDOJ 1157 HDU 1157 Who's in the Middle ACM 1157 IN HDU
- HDU 1711 HDOJ 1711 Number Sequence ACM 1711 IN HDU
- HDU 3016 HDOJ 3016 Man Down ACM 3016 IN HDU
- HDU 1512 HDOJ 1512 Monkey King ( 左偏树 ) ACM 1512 IN HDU
- HDOJ HDU 1171 Big Event ACM 1171 IN HDU