[HDU-1527] Getting started with the Wythoff game

Topic link: Take the stone game

Title

Two piles of stones are given to you. You can take any number of stones from one pile or the same number of stones from two piles, and the one who takes all the stones wins. Assuming that both sides adopt the optimal strategy, you are the first to ask if you are the winner or the loser.

answer

The classic Wythoff game.
Through analysis, we can get (assuming that the first pile of stones is smaller than the second pile of stones)
(0,0)
(1,2)
(3,5)
(4,7)
(6,10)
( 8,13 )
(9 , 15)
Such a pile of stones, no matter what the first move is to lose.
It can be seen that the difference of such pairs increases from 0, 1, 2, 3, 4, 5...
The first number is the smallest integer that has not appeared before.
In fact, there is such an interesting rule in the Wythoff game: the first number of a number pair = difference * 1.618 (rounded)

Code

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
//extern "C"{void *__dso_handle=0;}
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define lowbit(x) x&-x

const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


int sg[maxn];
int vis[maxn];

int main()
{
    
    
	int a,b;
	while(cin >> a >> b)
	{
    
    
		int minn=min(a,b);
		int maxx=max(a,b);
		double gold = (sqrt(5.0)+1)/2;
		int pre=(maxx-minn)*gold;
		if(pre==minn) cout << 0 << endl;
		else cout << 1 << endl;
	}
}

Guess you like

Origin blog.csdn.net/weixin_44235989/article/details/108217282