题意:略
国王和骑士用记忆搜索,注意骑士的移动是x-2,y-1或x-1,y-2。车是NIM博弈,后是威佐夫博弈。注意威佐夫博弈中两堆石子有大小之分,而输入不一定小在前。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,SSZ=*SZ,APB=,INF=0x7FFFFFFF,mod=;
const double GOLDSEP=(+sqrt())/2.0;
int dp1[SZ][SZ],dp2[SZ][SZ]; int dfs1(int x,int y)
{
if(dp1[x][y]!=INF)return dp1[x][y];
else if(x==&&y==)return dp1[x][y]=;
else
{
int dx[]={-,,-},dy[]={,-,-};
int LM=;
dp1[x][y]=;
for(int i=;i<LM;++i)
{
int nx=x+dx[i],ny=y+dy[i];
if(nx>=&&ny>=)
{
if(!dfs1(nx,ny))dp1[x][y]=;
}
}
return dp1[x][y];
}
} int dfs2(int x,int y)
{
//cout<<x<<" "<<y<<" "<<dp2[x][y]<<" "<<INF<<endl;
if(dp2[x][y]!=INF)return dp2[x][y];
else if(x==&&y==)return dp2[x][y]=-;
else if(!((x>=&&y>=)||(x>=&&y>=)))
{
//cout<<"here"<<(x>=3&&y>=2)<<" "<<x<<" "<<y<<endl;
return dp2[x][y]=;
}
else
{
int dx[]={-,-},dy[]={-,-};
int LM=,minv=INF;
for(int i=;i<LM;++i)
{
int nx=x+dx[i],ny=y+dy[i];
if(nx>=&&ny>=)
{
minv=min(minv,dfs2(nx,ny));
}
}
//cout<<"minv: "<<minv<<endl;
return dp2[x][y]=-minv;
}
} void init()
{
int type,ll,rr;
cin>>type>>ll>>rr;
--ll,--rr;
if(type==)
{
if(dfs1(ll,rr))cout<<'B'<<endl;
else cout<<'G'<<endl;
}
else if(type==)
{
if((ll^rr))cout<<'B'<<endl;
else cout<<'G'<<endl;
}
else if(type==)
{
int res=dfs2(ll,rr);
if(res==)cout<<'B'<<endl;
else if(res==)cout<<'D'<<endl;
else cout<<'G'<<endl;
}
else
{
if(ll>rr)swap(ll,rr);
if((int)(GOLDSEP*(rr-ll))==ll)
{
cout<<'G'<<endl;
}
else cout<<'B'<<endl;
}
} void work()
{ } int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
//freopen("d:\\2.txt","w",stdout);
lon casenum;
cin>>casenum;
for(int i=;i<SZ;++i)
{
for(int j=;j<SZ;++j)
{
dp1[i][j]=dp2[i][j]=INF;
}
}
//cout<<casenum<<endl;
for(lon time=;time<=casenum;++time)
//for(lon time=1;cin>>n>>len>>wid;++time)
{
init();
work();
}
return ;
}