题目链接:

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. 用hashmap实现自己的缓存

    @SuppressWarnings({"unchecked", "rawtypes"})public class DefaultCache implements ...

  2. GOF23种设计模式-工厂模式

    • 工厂模式: – 实现了创建者和调用者的分离. – 详细分类: • 简单工厂模式 • 工厂方法模式 • 抽象工厂模式 • 面向对象设计的基本原则: – OCP(开闭原则,Open-Closed Pr ...

  3. dll的使用

    2016-12-11   23:02:24 一:生成DLL 1:创建DLL工程 文件->新建->项目->visual c++->win32->win32控制台应用程序(w ...

  4. 怎样在ubuntu 系统上为 php 加上 redis 扩展

    近期一个项目.,想用redis 作为数据库,php是不待redis 扩展,必须安装,怎么安装呢?我在网上找的非常多资料发现都是预编译的.但都没成功.于是就找了第二种方法是不须要编译直接安装就能够了. ...

  5. ubuntu 卸载干净软件(包括配置文件)

    var/cache/apt/archives occupying huge space I am in the process of cleaning up my system. And I see ...

  6. 上传图片/文件到server

    package yao.camera.util; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; impo ...

  7. 前端学习——使用Ajax方式POST JSON数据包

    0.前言     本文解释怎样使用Jquery中的ajax方法传递JSON数据包,传递的方法使用POST(当然PUT又有时也是一个不错的选择).POST JSON数据包相比标准的POST格式可读性更好 ...

  8. 封装PDO操作数据库

    <?php class DatabaseHandler { /** * sql语句查询 */ public static function query_data ($dataName,$sql, ...

  9. struct platform_device中的id成员

    include/linux/platform_device.h #define PLATFORM_DEVID_NONE (-1) #define PLATFORM_DEVID_AUTO (-2) dr ...

  10. ORACLE 查看表结构

    select table_name from user_tables; //当前用户的表 select table_name from all_tables; //所有用户的表 select tabl ...