HDU 5754Life Winner Bo
Life Winner Bo
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1019 Accepted Submission(s): 373
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.
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
1 5 5
2 5 5
3 5 5
4 5 5
G
D
B
/* ***********************************************
Author :guanjun
Created Time :2016/7/27 13:04:59
File Name :hdu5754.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
const double Gsr=(+sqrt(.))/.;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int a,n,m; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--){
cin>>a>>n>>m;
if(a==){
if((n&)&&(m&))puts("G");
else puts("B");
}
if(a==){
if(n==m){//后手赢
puts("G");
}
else{
puts("B");
}
}
if(a==){
if(n<m)swap(n,m);
if((n==m)&&(n%==))puts("G");
else if((n%==)&&(m==n-))puts("B");
else puts("D");
}
if(a==){//威佐夫博弈
n--,m--;
if(n>m)swap(n,m);
if(n==(int)(Gsr*(m-n))){
puts("G");
}
else puts("B");
}
}
return ;
}
找规律。皇后的时候转换成博弈
“有两堆石子,每次可以在一堆里取任意(非空)颗(相当于是车的走法),或者在两堆里取相同(非空)颗(相当于是象的走法),取到最后一颗石子的人获胜,问先后手谁有必胜策略。”
HDU 5754Life Winner Bo的更多相关文章
- 5754Life Winner Bo
给定一个n*m的矩阵,有四种棋子(国际象棋的王,王后,骑士,车).起点在(1,1)先走到(n,m)获胜. 分析:车是nim博弈.王后是威佐夫博弈.王和骑士写两个1000*1000的预处理即可. hdu ...
- HDU 5754 Life Winner Bo (博弈)
Life Winner Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life W ...
- HDU 5754 Life Winner Bo 组合博弈
Life Winner Bo Problem Description Bo is a "Life Winner".He likes playing chessboard gam ...
- hdu_5754_Life Winner Bo(博弈)
题目链接:hdu_5754_Life Winner Bo 题意: 一个棋盘,有国王,车,马,皇后四种棋子,bo先手,都最优策略,问你赢的人,如果双方都不能赢就输出D 题解: 全部都可以直接推公式, 这 ...
- hdu-5754 Life Winner Bo(博弈)
题目链接: Life Winner Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- Life Winner Bo HDU - 5754
Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G. The size of ...
- HDU 5754 Life Winner Bo (找规律and博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5754 给你四种棋子,棋子一开始在(1,1)点,两个人B和G轮流按每种棋子的规则挪动棋子,棋子只能往右下 ...
- 【博弈论】HDU 5754 Life Winner Bo
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 题目大意: 4种棋子,象棋中的 1王,2车,3马,4后,选其一,B和G轮流走,不能往左上走,一 ...
- HDU 5754 Life Winner Bo(各类博弈大杂合)
http://acm.hdu.edu.cn/showproblem.php?pid=5754 题意: 给一个国际象棋的棋盘,起点为(1,1),终点为(n,m),现在每个棋子只能往右下方走,并且有4种不 ...
随机推荐
- 算法竞赛入门经典5.2 STL初步
1. 排序和检索,学会使用sort排序,以及low_bound函数 Raju and Meena love to play with Marbles. They have got a lot of m ...
- laravel学习笔记3--高级
一.artisan 1.基本使用: 1.1.查看基本命令: php artisan 1.2.查看具体命名的使用: php artisan help migrate 1.3.创建控制器: php art ...
- Android Studio + Genymotion模拟器安装与配置
一.Android studio 下载与安装 https://developer.android.google.cn/studio/index.html 进入谷歌官方链接下载Android studi ...
- windows下mysql 5.7版本中修改编码为utf-8的方法
方法如下 首先通过 show variables like 'character_set_%';查看mysql字符集情 默认编码为 latin1 然后关闭数据库 在mysql安装目录下找到my.ini ...
- C语言学习8
计算某日是该年的第几天 编写一个计算天数的程序,用户从键盘输入年.月.日,在屏幕中输出此日期是该年的第几天. /******************************************** ...
- postman工具的应用实战(二)
在接口测试工具中,最好的应该是soapui,jmeter,postman,但是soapui需要安装和破解,当然也是有破解版的,但是不够灵活,jmeter工具 做接口测试还是性能测试,功能测试,都是一个 ...
- BNUOJ 7178 病毒侵袭持续中
病毒侵袭持续中 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 30 ...
- Android BGABadgeView:显示提示数字(2)
Android BGABadgeView:显示提示数字(2) 在附录文章3的基础上,对代码进行稍微改造,显示在红色小圆球内部显示数字,同时给红色小圆球通过可编程调控红色小圆球的整体外观,布局文件 ...
- poj 1330lca模板题离线算法
#include<iostream> #include<vector> using namespace std; const int MAX=10001; int pre[MA ...
- 【NOIP2017练习】函数变换(DP,dfs)
题意: 思路: 极限步数大概不会超过30 ; ..max,..]of longint; eul:..max]of longint; cas,v,n,k,i,ans,j:longint; functio ...