【bzoj3298】[USACO 2011Open]cow checkers(博弈论)

  题目传送门: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=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)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=1;
    for(int i=1;;i++){
        while(vis[now])++now;
        if(now>n||now>m)break;
        vis[now]=1; vis[now+i]=1;
        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

 

posted @ 2018-10-01 20:41  QuartZ_Z  阅读(201)  评论(0编辑  收藏  举报