1. 程式人生 > >湖南大學第十四屆ACM程式設計大賽 I II play with GG

湖南大學第十四屆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;
}