题目链接:

Life Winner Bo

Time Limit: 2000/1000 MS (Java/Others)    

Memory Limit: 131072/131072 K (Java/Others)

Problem Description
Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G.

The size of the chessboard is N×M.The top left corner is numbered(1,1) and the lower right corner is numberd (N,M).

For each game,Bo and G take turns moving a chesspiece(Bo first).At first,the chesspiece is located at (1,1).And the winner is the person who first moves the chesspiece to (N,M).At one point,if the chess can't be moved and it isn't located at (N,M),they end in a draw.

In general,the chesspiece can only be moved right or down.Formally,suppose it is located at (x,y),it can be moved to the next point (x′,y′) only if x′≥x and y′≥y.Also it can't be moved to the outside of chessboard.

Besides,There are four kinds of chess(They have movement rules respectively).

1.king.

2.rook(castle).

3.knight.

4.queen.

(The movement rule is as same as the chess.)

For each type of chess,you should find out that who will win the game if they both play in an optimal strategy.

Print the winner's name("B" or "G") or "D" if nobody wins the game.

 
Input
In the first line,there is a number T as a case number.

In the next T lines,there are three numbers type,N and M.

"type" means the kind of the chess.

T≤1000,2≤N,M≤1000,1≤type≤4

 
Output
For each question,print the answer.
 
Sample Input
4
1 5 5
2 5 5
3 5 5
4 5 5
 
Sample Output
G
G
D
B
 
题意:
 
四种棋子,king rook knight,queen;然后看谁先从(1,1)到(n,m);
 
思路:
 
前三种画图都可以找到位置的关系;可以把位置直接标出来;queen的是威佐夫博弈;
 
AC代码:
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=2e6+10;
const int maxn=500+10;
const double eps=1e-8; int flag;
void dfs(int x,int y)
{
// cout<<x<<" "<<y<<endl;
if(x==1&&y==1){flag=-1;return ;}
if(x<1||y<1)return ;
int fx,fy;
fx=x-1,fy=y-2;
if(fx==1&&fy==1){flag=1;return ;}
fx=x-2;fy=y-1;
if(fx==1&&fy==1){flag=1;return ;}
fx=x-3;fy=y-3;
dfs(fx,fy);
} int main()
{
//freopen("in.txt","r",stdin);
int t;
read(t);
while(t--)
{
int type,n,m;
read(type);read(n);read(m);
if(type==1)
{
if((n-1)%2||(m-1)%2)printf("B\n");
else printf("G\n");
}
else if(type==2)
{
if(n==m)printf("G\n");
else printf("B\n");
}
else if(type==3)
{
flag=0;
dfs(n,m);
//if(n==1&&m==1)flag=0;
if(flag==0)printf("D\n");
else if(flag==1)printf("B\n");
else printf("G\n");
}
else
{
if(n<m) swap(n,m);
n--;m--;
int k=n-m;
n=(int)(k*(1+sqrt(5))/2.0);
if(n==m) printf("G\n");
else printf("B\n");
}
} return 0;
}

  

hdu-5754 Life Winner Bo(博弈)的更多相关文章

  1. HDU 5754 Life Winner Bo (博弈)

    Life Winner Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life W ...

  2. HDU 5754 Life Winner Bo 组合博弈

    Life Winner Bo Problem Description   Bo is a "Life Winner".He likes playing chessboard gam ...

  3. HDU 5754 Life Winner Bo (找规律and博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5754 给你四种棋子,棋子一开始在(1,1)点,两个人B和G轮流按每种棋子的规则挪动棋子,棋子只能往右下 ...

  4. HDU 5754 Life Winner Bo(各类博弈大杂合)

    http://acm.hdu.edu.cn/showproblem.php?pid=5754 题意: 给一个国际象棋的棋盘,起点为(1,1),终点为(n,m),现在每个棋子只能往右下方走,并且有4种不 ...

  5. HDU 5754 Life Winner Bo (各种博弈) 2016杭电多校联合第三场

    题目:传送门 题意:一个国际象棋棋盘,有四种棋子,从(n,m)走到(1,1),走到(1,1)的人赢,先手赢输出B,后手赢输出G,平局输出D. 题解:先把从(n,m)走到(1,1)看做是从(1,1)走到 ...

  6. 【博弈论】HDU 5754 Life Winner Bo

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 题目大意: 4种棋子,象棋中的 1王,2车,3马,4后,选其一,B和G轮流走,不能往左上走,一 ...

  7. HDU 5754 Life Winner Bo

    四种棋子实质上都是一样的思路: 如果某位置的棋子,它下一步可以走到的位置中 能找到有后手胜的位置,那么该位置先手必胜. 如果某位置的棋子,它下一步可以走到的位置中 全是先手胜,那么该位置后手必胜. 其 ...

  8. hdu 5754 Life Winner Bo 博弈论

    对于king:我是套了一个表. 如果起点是P的话,则是后手赢,否则前手赢. 车:也是画图推出来的. 马:也是推出来的,情况如图咯. 对于后:比赛时竟然推错了.QAQ最后看了题解:是个威佐夫博奕.(2, ...

  9. hdu_5754_Life Winner Bo(博弈)

    题目链接:hdu_5754_Life Winner Bo 题意: 一个棋盘,有国王,车,马,皇后四种棋子,bo先手,都最优策略,问你赢的人,如果双方都不能赢就输出D 题解: 全部都可以直接推公式, 这 ...

随机推荐

  1. Handler处理机制

    handler缺点:如果要运送两种类型的数据(比如一个Bitmap,一个Object)就不能运送,但可以用Bunder来传输  *    使用handler的步骤:  *    1.创建一个handl ...

  2. Neural Networks and Deep Learning学习笔记ch1 - 神经网络

    近期開始看一些深度学习的资料.想学习一下深度学习的基础知识.找到了一个比較好的tutorial,Neural Networks and Deep Learning,认真看完了之后觉得收获还是非常多的. ...

  3. iOS开发 CGBitmapContextCreate

    最近项目中,需要对图片进行各种操作. 使用CGBitmapContextCreate 创建位图上下文. CG_EXTERN CGContextRefCGBitmapContextCreate(void ...

  4. Linux文件内容查阅

    直接查阅一个文件的内容:cat/tac/nl命令 cat (concatenate) # cat [-AbEnTv] 选项与參数: -A  :相当於 -vET 的整合选项.可列出一些特殊字符而不是空白 ...

  5. PHP_EOL是什么意思?

      PHP_EOL 代表php的换行符, 这个变量会根据平台而变, 在windows下会是/r/n, 在linux下是/n, 在mac下是/r             文章来源:刘俊涛的博客 地址:h ...

  6. [ssh新闻公布系统三]存储新闻

    一.存储新闻dao方法 在NewsDao.java中新增存储新闻的saveOrupdate方法 public void saveOrupdate(News news){ getSession().sa ...

  7. js json 对象

    JSON 语法规则 JSON 语法是 JavaScript 对象表示法语法的子集. 数据在名称/值对中 数据由逗号分隔 大括号保存对象 中括号保存数组 JSON 名称/值对 JSON 数据的书写格式是 ...

  8. MySQL:unknown variable &#39;master-host=masterIP&#39; [ERROR] Aborting

    <span style="font-size:18px;">120401 15:45:44 [ERROR] C:\Program Files\MySQL\MySQL S ...

  9. 使用HtmlUnit登录百度

    环境 java 1.7 HtmlUnit 2.18 eclipse 4.4.2 maven 配置: <dependency> <groupId>net.sourceforge. ...

  10. webpack实用配置总结

    1.webpack.config.js配置文件为: //处理共用.通用的js var webpack = require('webpack'); //处理html模板 var htmlWebpackP ...