Problem Statement
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of XX and YY stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice:
- Take 2i2i stones from one of the piles. Then, throw away ii of them, and put the remaining ii in the other pile. Here, the integer ii (1≤i)(1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.
The player who becomes unable to perform the operation, loses the game.
Given XX and YY, determine the winner of the game, assuming that both players play optimally.
Constraints
- 0≤X,Y≤10180≤X,Y≤1018
Input
Input is given from Standard Input in the following format:
XX YY
Output
Print the winner: either Alice
or Brown
.
Sample Input 1 Copy
Copy
2 1
Sample Output 1 Copy
Copy
Brown
Alice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory.
Sample Input 2 Copy
Copy
5 0
Sample Output 2 Copy
Copy
Alice
Sample Input 3 Copy
Copy
0 0
Sample Output 3 Copy
Copy
Brown
Sample Input 4 Copy
Copy
4 8
Sample Output 4 Copy
Copy
Alice
题意:
给你两堆石子第一堆x个,第二堆y个,A先手可以从一堆偶数个石子,一半扔掉一半放另一堆里。谁先不能操作谁就输。
思路:
转自https://www.cnblogs.com/ww3113306/p/9819252.html
结论:如果|x−y|<=1|x−y|<=1那么后手必赢,反之先手必赢。
证明:
假设现在有|x−y|≤1|x−y|≤1,我们不妨设x>yx>y,那么y=x−ky=x−k.所以如果我们从x中拿出2i个石子,那么x,y将变为:
x′=x−2ix′=x−2i y′=x−k+iy′=x−k+i
这时我们可以发现y′−x′=−k+3iy′−x′=−k+3i,因为i是非负的,而k因为|x−y|≤1|x−y|≤1,所以k≤1k≤1,所以3i的大小至少为3,而k最大为1,所以y′−x′y′−x′至少为2,那么这个时候后手一定可以移动。
现在来考虑后手怎么动:
首先我们可以推出一个性质,当一开始的石子数为x , y时,先手取了一步变成了x−2ix−2i和y+iy+i,这个时候后手只需要从y中拿同样的2i个,就可以使得石子数变为x−ix−i和y−iy−i,而我们知道,两个数同时减去同一个数,它们的差是不会变化的,所以这个时候的x′x′和y′y′依然相差小于等于1,这就转化成了第一种情况
代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll x,y;
cin>>x>>y;
if(abs(x-y)<=1)
{
cout<<"Brown";
}
else
{
cout<<"Alice";
}
}