题意:略

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

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...

  2. QSS独门秘籍:subcontrol

    QSS是C++ Qt中的界面美化神器,其语法和CSS区别不大,但是QSS有一个独有的功能——subcontrol,这是CSS所没有的,一个widget往往由多个子部件构成,利用subcontrol可以 ...

  3. python框架之Django(7)-Cookie&Session使用

    Cookie 添加 response.set_cookie 添加明文cookie response.set_cookie(key, value='', max_age=None, expires=No ...

  4. Number 强制类型转换 int 强制转换整型 float 强制转换浮点型 complex 强制转换成复数 bool 强制转换成布尔类型,结果只有两种,要么True 要么 False """bool 可以转换所有的数据类型 everything"""

    # ###Number 强制类型转换 var1 = 5 var2 = 4.85 var3 = True var3_2 = False var4 = 3+9j var5 = "888777&q ...

  5. iOS UI基础-21 WKWebView

    WKWebView,直接显示网页,需要引入第三方类:https://github.com/marcuswestin/WebViewJavascriptBridge 加上进度条代码,很完美使用 webV ...

  6. mysql----------mysql5.7.11导入sql文件时报错This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled

    1.导入sql文件出现如下错误. [Err] 1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in ...

  7. laravel 比较好的资料地址 看云

    https://www.kancloud.cn/curder/laravel/408497

  8. 一个不错的git资源站点

    https://backlog.com/git-tutorial/cn/stepup/stepup2_8.html

  9. 解救小哈——bfs广搜

    问题描述: 小哈去玩迷宫,结果迷路了,小哼去救小哈.迷宫由n行m列的单元格组成(n和m都小于等于50),每个单元格要么是空地,要么是障碍物. 问题:帮小哼找到一条从迷宫的起点通往小哈所在位置的最短路径 ...

  10. Godot必须明确掌握的概念与知识

    本文对godot必须掌握的概念进行罗列,以便于浏览学习: (随时补充) 1.场景 2.节点 X:场景与节点 3.脚本(建议直接学习GDscript,当然掌握C#也可以) 4.类