题意:略

国王和骑士用记忆搜索,注意骑士的移动是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 ;
}

hdoj5754的更多相关文章

随机推荐

  1. Python------mysql数据库

    import pymysql #一.直接连接mysql数据库'''coon=pymysql.connect(host='192.168.*.*',user='root',password='12345 ...

  2. Web开发——JavaScript基础(JSON教程)

    参考: JSON:JavaScript 对象表示法(JavaScript Object Notation). JSON 是存储和交换文本信息的语法.类似 XML. JSON 比 XML 更小.更快,更 ...

  3. MAC OSX Xcode硬盘清理

    1.移除对旧设备的支持影响:可重新生成:再连接旧设备调试时,会重新自动生成.我移除了4.3.2, 5.0, 5.1等版本的设备支持.路径:~/Library/Developer/Xcode/iOS D ...

  4. luogu3978 [TJOI2015]概率论

    题目链接:洛谷 题目大意:求所有$n$个点的有根二叉树的叶子节点数总和/$n$个点的有根二叉树的个数. 数据范围:$n\leq 10^9$ 生成函数神题!!!!(我只是来水博客的) 首先$n$个点的有 ...

  5. Failed to load driver class com.mysql.jdbc.Driver from HikariConfig class classloader sun.misc.Launcher$AppClassLoader@18b4aac2

    1.错误日志 Failed to load driver class com.mysql.jdbc.Driver from HikariConfig class classloader sun.mis ...

  6. python线程、协程、I/O多路复用

    目录: 并发多线程 协程 I/O多路复用(未完成,待续) 一.并发多线程 1.线程简述: 一条流水线的执行过程是一个线程,一条流水线必须属于一个车间,一个车间的运行过程就是一个进程(一个进程内至少一个 ...

  7. Redis配置文件redis.conf详解

    一.Redis配置文件redis.conf详解 # Note on units: when memory size is needed, it is possible to specifiy # it ...

  8. linux挂载概念简述:

    挂载概念简述: 根文件系统之外的其他文件要想能够被访问,都必须通过“关联”至根文件系统上的某个目录来实现,此关联操作即为“挂载”,此目录即为“挂载点”,解除此关联关系的过程称之为“卸载” 1.挂载:根 ...

  9. [macOS] error when brew updating

    I want to update the brew, then run brew update but unluckly, i got these error /usr/local/Library/b ...

  10. ANNOTATION 注解

    注解(Annotation)很重要,未来的开发模式都是基于注解的,JPA是基于注解的,Spring2.5以上都是基于注解的,Hibernate3.x以后也是基于注解的,现在的Struts2有一部分也是 ...