首页 > ACM题库 > HDU-杭电 > HDU 1564 Play a game-博弈论-[解题报告] C++
2013
12-12

HDU 1564 Play a game-博弈论-[解题报告] C++

Play a game

问题描述 :

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?

输入:

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.

输出:

Output the winner ("8600" or "ailyanlu") for each input line except the last zero.
No other characters should be inserted in the output.

样例输入:

2
0

样例输出:

8600

http://acm.hdu.edu.cn/showproblem.php?pid=1564

题意:给定一个N*N的方块 起始点处于一个角上 然后两个人可以轮流将棋子往没有访问过的一个方向移动 不能移动的一方就输了。

分析:我直接觉得结果可以通过n的奇偶性来判断。然后就过了。其实这题我是凑巧的。

证明在这里:http://blog.csdn.net/topc0o0der/article/details/5928391。还没看懂。

//============================================================================
// Name        : hdu.cpp
// Author      : lanjiangzhou
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<cstdio>

using namespace std;

int main() {
    int n;
    while(scanf("%d",&n)!=EOF){
        if(n==0) break;
        if(n%2==0) printf("8600\n");
        else printf("ailyanlu\n");
    }
    return 0;
}

 

解题报告转自:http://www.cnblogs.com/lanjiangzhou/archive/2013/04/13/3019046.html


  1. 算法是程序的灵魂,算法分简单和复杂,如果不搞大数据类,程序员了解一下简单点的算法也是可以的,但是会算法的一定要会编程才行,程序员不一定要会算法,利于自己项目需要的可以简单了解。

  2. 这道题目的核心一句话是:取还是不取。
    如果当前取,则index+1作为参数。如果当前不取,则任用index作为参数。