hdoj5754
题意:略
国王和骑士用记忆搜索,注意骑士的移动是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的更多相关文章
随机推荐
- PHP调用接口用post方法传送json数据
1.核心代码: <?php require("helper.php"); header('content-type:text/html;charset=utf-8'); $k ...
- Jmeter学习之-获取登录的oken值(2)
此篇介绍获取登录token的第二种方式--json提取器提取 PS:此方法针对接口返回值为json串格式 在登录请求上右键添加JSON提取器 ...
- MongoDB 目录
MongoDB 介绍 centos7.6 安装与配置 MongoDB yum方式 MongoDB 数据库操作 MongoDB 用户管理 MongoDB 新建数据库和集合 查询集合 MongoDB 增删 ...
- Windows路由表
对于路由器的路由表,网管都很熟悉,但是windows的路由表,可能了解的人就相对少一些.今天我们就一起来看看windows路由表. 一.windows路由表 1.使用命令 route print 查看 ...
- 免费的文件比较工具和beyondcomare和source insight的比较工具
Linux下,meld就够了,命令行用用diff也行,kdiff3也不错. 参考 http://www.cnblogs.com/itech/archive/2009/08/13/1545344.htm ...
- vscode/webstorm快捷键
ctrl+/ 单行 [alt+shift+A] 多行注释 (默认的 我已经修改了) 复制当前行:shift + alt +up/down(上下箭头)可以修改成ctrl+d(改成webstorm一 ...
- Go 初体验 - 令人惊叹的语法 - defer.2 - 如何提前执行?
上一文中讲到 defer 会在宿主函数 return 之前调用,那么我们就是想在宿主函数执行到中间调用,怎么办呢? 1. 改变宿主函数逻辑,分成多个函数,需要的那个函数里 defer . 2. 使用匿 ...
- php判断手机段登录,以及phpcms手机PC双模板调用
首先一段php代码判断是否为手机浏览: function isMobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP ...
- 【2017-05-18】WebForm的Repeater控件及简单控件
<%@ %> - 这里面写一些声明和引用的 <% %> - 编写C#代码的 <%= %> - 往界面上输出一个变量的值 <%# Eval("属性名 ...
- python报错之OSError
刚刚练一下xlrd模块的时候,竟然报错了! 百度了一下,才知道,是自己直接复制粘贴导致的:最好直接搜索\u202a才找到解决办法 所以只需从写换个地方复制路径或则重新手动输入一次就解决了 参考链接:h ...