题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=3298

  博弈论经典结论题,我也没什么好说的。matrix67大佬比我想得深入的多:捡石子游戏、 Wythoff 数表和一切的 Fibonacci 数列

  代码:

#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define ull unsigned long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 2000010
inline ll read(){ll tmp=; char c=getchar(),f=; for(;c<''||''<c;c=getchar())if(c=='-')f=-; for(;''<=c&&c<='';c=getchar())tmp=(tmp<<)+(tmp<<)+c-''; return tmp*f;}
inline ll power(ll a,ll b){ll ans=; for(;b;b>>=){if(b&)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
using namespace std;
int vis[maxn];
int a[maxn];
int n,m;
int main()
{
n=read(); m=read();
int now=;
for(int i=;;i++){
while(vis[now])++now;
if(now>n||now>m)break;
vis[now]=; vis[now+i]=;
a[now+i]=now; a[now]=now+i;
}
int t=read();
while(t--){
int n=read(),m=read();
if(a[n]==m)printf("Farmer John\n");
else printf("Bessie\n");
}
}

bzoj3298

05-11 18:18