II play with GG(思维规律)

时间限制: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

思路:这个题的常规解法应该是SG函数,但是自己在纸上推一下能发现如代码所示的规律

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	if(a%2==0&&b%2==0)
	{
		cout<<"gg"<<endl;
	}
	else
	{
		cout<<"ii"<<endl;
	}
	
	return 0;
} 
原文地址:https://www.cnblogs.com/Staceyacm/p/10781856.html