Experimental Educational Round: VolBIT Formulas Blitz(R)博弈

R. Game
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.

The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.

The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.

Input

The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.

Output

Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.

Examples
input
1
output
1
input
2
output
2



题意:有2个人在棋盘上涂色,各持一种颜色,相同的颜色不能相邻,现在给你n*n的棋盘,问先手赢还是后手赢?



题解:我是瞎猜的,莫名AC了。。。看了下官方题解,不是很懂,大概意思是只要将画在先手的对角线的地方就是最优的。那么我们需要考虑奇偶就可以了

For the field of an even size there is a winning strategy for the second player. Namely, to paint a cell that is symmetrical with respect to the center of the field to the cell painted by the first player on the previous turn. After each turn of the second player the field is centrosymmetrical and so there is always a cell that can be painted that is symmetrical with respect to the center of the field to any cell that the first player can choose to paint.

.... 1... .1.. .... .... .... .... .... 1... .1.. .... .... .... ...2 ..2. .... ...2 ..2. .... ....

For the field of an odd size there is a winning strategy for the first player. Namely, on the first turn to paint the central cell, then to paint a cell that is symmetrical with respect to the center of the field to the cell painted by the second player on the previous turn. After each turn of the first player the field is centrosymmetrical and so there is always a cell that can be painted that is symmetrical with respect to the center of the field to any cell that the second player can choose to paint.

..... 2.... .2... ..2.. ..... ..... ..... ..... ..... .2... ..1.. ..1.. ..1.. ..1.. ..1.. ..... ..... ..... ..... ...1. ..... ....1 ...1. ..1.. .....

So for even n the answer is 2, for odd n the answer is 1. One of the possible formulas for the problem is .

n can be up to 1018 so at least 64-bit integer type should be used to input it.



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
using namespace std;
#define N 1000+5

typedef long long LL;  
int main()
{
#ifdef CDZSC
	freopen("i.txt","r",stdin);
#endif
	LL n;
	cin>>n;
	printf("%d\n",(n&1)?1:2);
	return 0;
}











你可能感兴趣的:(Experimental Educational Round: VolBIT Formulas Blitz(R)博弈)