hdu2147 kiki's game(巴什博弈java)

举报
bigsai 发表于 2021/02/03 02:26:27 2021/02/03
【摘要】 题目链接 kiki’s game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Java/Others) Total Submission(s): 13497 Accepted Submission(s): 8238 Problem Description Recently ki...

题目链接
kiki’s game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Java/Others)
Total Submission(s): 13497 Accepted Submission(s): 8238

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<=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!
意思是一个棋子只能往左面,下面,或者左下走。不能走的那个输。kiki先走。
分析一下走法:

O O O O O O O O 
O O O O O O O O 
O O O O O O O O 
O O O O O O O O 
O O O O O O O O 
O O O O O O O O 
O O O O O O O O 
O O O O O O O O 

NNNNNNNN
PNPNPNPN
NNNNNNNN
PNPNPNPN
NNNNNNNN
PNPNPNPN
NNNNNNNN
PNPNPNPN

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

先考虑走直线,不难发现:如果走直线,向左,向下。从左下角开始找P/N点。画出图。

  • 必败点(P点) :前一个选手(Previous player)将取胜的位置称为必败点。
  • 必胜点(N点) :下一个选手(Next player)将取胜的位置称为必胜点。
    最后一个点(左下角必败),因为他的前一个人走到该点他就输了。
    相反,他的附近三个点都是必胜点,因为这个人走一步就赢了。
    所以分析pn图可以发现(n%2==0)或者(m%2= =0)都是 必胜的。
    附上代码如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class hdu2147 {

	public static void main(String[] args) throws IOException {
		StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); while(in.nextToken()!=StreamTokenizer.TT_EOF) { int n=(int)in.nval; in.nextToken(); int m=(int)in.nval; if(m==0&&n==0) {break;} if(m%2==0||n%2==0) { out.println("Wonderful!"); } else {out.println("What a pity!");} out.flush(); }
	}
}


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

文章来源: bigsai.blog.csdn.net,作者:Big sai,版权归原作者所有,如需转载,请联系作者。

原文链接:bigsai.blog.csdn.net/article/details/82874148

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。