湖南大学第十四届ACM程序设计大赛 I II play with GG

链接:https://ac.nowcoder.com/acm/contest/338/I
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

IG won the S championship and many people are excited, ii and gg are no exception. After watching the game, the two of them also want to play a game.
There is now an infinite chessboard with only one piece. Initially the pieces are placed at the (x, y) position (the board coordinates are counted from 0). They took turns to move the pieces. ii moves first.
There are three ways to move
1. Move the piece to the left by one space (from (x, y) to (x-1, y)).
2. Move the piece down one space (from (x, y) to (x, y-1)).
3. Move the piece to the lower left by one space (from (x, y) to (x-1, y-1)).
It should be noted that the pieces cannot be removed from the board.
The first  person who can not operate is judged negative (in other words, the first person who moves the piece to (0,0) wins).
Now give the initial coordinates x, y of the piece. Under the premise that both take the optimal strategy, please output the name of the winner (ii or gg).

输入描述:

The input contains only one line. Enter two integers x  y to represent the initial coordinates of the piece. (0<=x, y<=1000)。

输出描述:

the winner's name (ii or gg)。

示例1

输入

复制

1 1

输出

复制

ii

示例2

输入

复制

124 654

输出

复制

gg

题目大意:

IG赢得了S冠军,很多人都很兴奋,II和GG也不例外。看完比赛后,他们两个还想玩一场。
现在有一个只有一块的无限棋盘。最初,棋子放置在(x,y)位置(板坐标从0开始计数)。他们轮流移动棋子。II首先移动。
有三种移动方式
1。将棋子向左移动一个空格(从(x,y)到(x-1,y))。
2。将棋子向下移动一个空间(从(x,y)到(x,y-1))。
三。将棋子向左下方移动一个空格(从(x,y)到(x-1,y-1))。
应该注意的是,这些棋子不能从板上拆下。
第一个不能操作的人被判为失败(换句话说,第一个将棋子移动到(0,0)的人获胜)。
现在给出棋子的初始坐标x,y。在双方都采取最优策略的前提下,请输出获胜者的姓名(II或GG)。

输入仅包含一行。输入两个整数x y来表示工件的初始坐标。(0<=X,Y<=1000)。

输出获胜者姓名(II或GG)。

这个博弈题很有意思,笔者先提供简单思路,之后会在后续博客中细讲此题。

1.结束状态为P状态。(已经到了结束状态,故先手必败)
2.所有下一状态中全为N状态,则当前状态为P状态。 (不管你往哪
走,你的对手都必胜,所以你必败)
3.所有下一状态中存在P状态,则当前状态为N状态。(只要你能
走到让你对手必败的情况,你现在就是必胜)
pnpnpnpnpnpnpnpnpnpnpn

npnpnpnpnpnpnpnpnpnpnp

pnpnpnpnpnpnpnpnpnpnpn

npnpnpnpnpnpnpnpnpnpnp   (棋盘的状态,p为败,n为胜)

观察不难发现,必败点的坐标依次为(0,0)、 (2,0)、 (0,2)、 (0,4)、 (2,4)、 (4,4)、 (4,2)、 (4,0);
所以结论为:当x%2==0&&y%2==0时,先手必败 否则先手必胜。
 

#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a%2==1||b%2==1)
    cout<<"ii"<<endl;
    else
    cout<<"gg"<<endl;
}

猜你喜欢

转载自blog.csdn.net/basketball616/article/details/86288151
gg
今日推荐