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的更多相关文章
随机推荐
- pytorch-MNIST数据模型测试
用pytorch搭建一个DNN网络,主要目的是熟悉pytorch的使用 """ test Function """ import torch ...
- CentOS7.6 安装Docker
删除已安装的Docker # Uninstall installed docker sudo yum remove docker \ docker-client \ docker-client-lat ...
- python 模块大全
logging time datetime sys os json random hashlib paramiko pymysql模块使用 subprocess pywi ...
- 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 ...
- Vue使用Typescript开发编译时提示“ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'afterCompile' of undefined”的解决方法
使用Typescript开发Vue,一切准备就绪.但npm start 时,提示“ ERROR in ./src/main.tsModule build failed: TypeError: Cann ...
- PHP----------安装包lnmp1.3-full安装的lnmp环境,如何安装PHP扩展
1. 如果已经安装LNMP套件,请按以下步骤处理 a. 跳转到fileinfo源代码目录` cd /root/downloads/lnmp1.2-full/src/php-7.0.7/ext/file ...
- linux 下tftpf搭建
什么是TFTP服务 TFTP(Trivial File Transfer Protocol,简单文件传输协议) 是TCP/IP协议族中的一个用来在客户机与服务器之间进行 简单文件传输的协 ...
- IP2——IP地址和子网划分学习笔记之《子网掩码详解》
2018-05-04 16:21:21 在学习掌握了前面的<进制计数><IP地址详解>这两部分知识后,要学习子网划分,首先就要必须知道子网掩码,只有掌握了子网掩码这部分内容 ...
- VCS
timing check相关的, +notimingcheck命令,可以用在compile时,也可以用在run time的时候, 都是将检查timing的系统函数,都disable掉了, 加在comp ...
- day04 一个简单的代码优化案例
import random punches = ['石头','剪刀','布'] computer_choice = random.choice(punches) user_choice = input ...