题解报告:hdu 1564 Play a game(找规律博弈)
Posted 霜雪千年
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了题解报告:hdu 1564 Play a game(找规律博弈)相关的知识,希望对你有一定的参考价值。
Problem Description
New Year is Coming! ailyanlu is very happy today! and he is playing a chessboard game with 8600.The size of the chessboard is n*n. A stone is placed in a corner square. They play alternatively with 8600 having the first move. Each time, player is allowed to move the stone to an unvisited neighbor square horizontally or vertically. The one who can\'t make a move will lose the game. If both play perfectly, who will win the game?
新年快到了!ailyanlu今天很开心!他正在玩8600棋盘游戏。棋盘的大小是n * n。一块石头被放置在角落广场。8600有先移动的机会。每次玩家都可以将石头水平或垂直移动到未访问的邻居广场。无法采取行动的人将失去这场比赛。如果两者都完美发挥,谁会赢得比赛?
新年快到了!ailyanlu今天很开心!他正在玩8600棋盘游戏。棋盘的大小是n * n。一块石头被放置在角落广场。8600有先移动的机会。每次玩家都可以将石头水平或垂直移动到未访问的邻居广场。无法采取行动的人将失去这场比赛。如果两者都完美发挥,谁会赢得比赛?
Input
The input is a sequence of positive integers each in a separate line.
The integers are between 1 and 10000, inclusive,(means 1 <= n <= 10000) indicating the size of the chessboard. The end of the input is indicated by a zero.
The integers are between 1 and 10000, inclusive,(means 1 <= n <= 10000) indicating the size of the chessboard. The end of the input is indicated by a zero.
输入是一系列正整数,每个单独一行。整数在1到10000之间(表示1 <= n <= 10000),表示棋盘的大小。输入的结尾用零表示。
Output
Output the winner ("8600" or "ailyanlu") for each input line except the last zero. No other characters should be inserted in the output.
输出每个输入行的胜者(“8600”或“ailyanlu”),除了最后一个零。输出中不应插入其他字符。
Sample Input
2
0
Sample Output
8600
解题思路:找规律博弈。题目的意思就是轮到的人只能上或下或左或右移1格到未访问的格子,并且两者完美发挥,最后无法移动的人将输掉比赛。
举3个栗子:①当n=1(奇数)时,先手不能移动,则后手必赢;
②当n=2(偶数)时,两者移动如图所示(都是最优策略):易得先手必赢
③当n=3(奇数)时,两者移动如图所示(都是最优策略):易得后手必赢
再举多个例子的过程中我们可以发现:当n为奇数时,后手只要按照螺旋线的走法(最优策略),最后一步必到中心方格,此时先手无法再移动,即后手必赢;当n为偶数时,同样,按照螺旋线的走法(最优策略),最后一步必轮到先手,此时后手无法移动,即先手必赢。
因此,可得出结论:当n为奇数时,“8600”先手必赢;反之,“ailyanlu”后手必赢。
AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n; 6 while(cin>>n && n){ 7 if(n%2==0)cout<<"8600"<<endl;//先手必赢 8 else cout<<"ailyanlu"<<endl;//后手必赢 9 } 10 return 0; 11 }
以上是关于题解报告:hdu 1564 Play a game(找规律博弈)的主要内容,如果未能解决你的问题,请参考以下文章