Life Winner Bo HDU - 5754
Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G.
The size of the chessboard is N×MN×M.The top left corner is numbered(,)(,) and the lower right corner is numberd (N,M)(N,M).
For each game,Bo and G take turns moving a chesspiece(Bo first).At first,the chesspiece is located at (,)(,).And the winner is the person who first moves the chesspiece to (N,M)(N,M).At one point,if the chess can't be moved and it isn't located at (N,M)(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)(x,y),it can be moved to the next point (x′,y′)(x′,y′) only if x′≥xx′≥x and y′≥yy′≥y.Also it can't be moved to the outside of chessboard.
Besides,There are four kinds of chess(They have movement rules respectively).
.king.
.rook(castle).
.knight.
.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 TT as a case number.
In the next TT lines,there are three numbers type,NN and MM.
"type" means the kind of the chess.
T≤,≤N,M≤,≤type≤4T≤,≤N,M≤,≤type≤
Output
For each question,print the answer.
Sample Input
Sample Output
G
G
D
B
Problem Description
以下解释参考:
https://blog.csdn.net/xtulollipop/article/details/52046874
https://www.cnblogs.com/Ritchie/p/5708601.html
我也看了老半天,真是渣渣
问给一种棋子,两人轮流走,只能向右或下下走,最后到N,M的赢。
1、王(King):横、直、斜都可以走,但每次限走一步
2、车(Rook):横、竖均可走,不能斜走,格数不受限制,除王车易位的情况下,平时不能越子
3、马(Knight):每步棋先横走或竖走一格,再斜走一格(或者横两格竖一格,竖两格横一格),可以越子
4、后(Queen):横、竖、斜都可以走,格数不受限制,但不能越子
1.王 拿SG预处理一下

你也可以找出规律发现:当n和m全为奇数时,先手必败。
2.车 到达终点时总要走n行,m列。可以把他们看成Nim的两堆石子。Nim游戏 ,异或一下
3.马 因为我们只考虑必胜必败态,其他的可能赢或输的点,我总是不走过去,会使得这个是平局。。打表

观察图表:先n--,m--,把问题转化为(0,0)是终点,如果n+m不是3的倍数一定是平局;如果是3的倍数,如果nm相等,那么一定是必败的,先手减2减1,后手就减1减2,必败;如果nm不等且n=m+1或者m=n+1,那么先手必胜,因为可以一步走到必败点,必胜;其余情况都是平局,因为如果一方存在赢的情况,另一方可以不走那步,把小的数-2,大的数-1,往墙上靠,谁也赢不了肯定是平局。
4.后 和车一样考虑,就是可以拿任意堆任意个,或者拿两堆同时拿任意个,是一个标准的威佐夫博弈
AC Code:
1.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std; bool SG[][];
int SG3[][];
int a,n,m; bool visit[];
void getSG1(){
memset(SG,,sizeof(SG));
for(int i=;i<=;i++){
for(int j=;j<=;j++){
memset(visit,,sizeof(visit));
if(i->) visit[SG[i-][j]]=true;
if(j->) visit[SG[i][j-]]=true;
if(i->&&j->)visit[SG[i-][j-]]=true;
for(int k=;;k++){
if(visit[k]==){
SG[i][j]=k;
break;
}
}
}
}
}
void getSG3(){
memset(SG3,-,sizeof(SG3));
SG3[][]=;
for(int i=;i<=;i=i+){
SG3[i][i]=;
SG3[i-][i-]=;
SG3[i-][i-]=;
}
}
int main(){
int t;
scanf("%d",&t);
getSG1();
getSG3();
while(t--){
scanf("%d %d %d",&a,&n,&m);
if(n>m) swap(n,m);
if(a==){
if(SG[n][m]) printf("B\n");
else printf("G\n");
}
else if(a==){
if((n^m)) printf("B\n");
else printf("G\n");
}
else if(a==){
if(SG3[n][m]==) printf("B\n");
else if(SG3[n][m]==-)printf("D\n");
else printf("G\n");
}
else if(a==){
n--;
m--;
if(n<m) swap(n,m);
int k=n-m;
n=(int)(k*(+sqrt())/2.0);
if(n==m) printf("G\n");
else printf("B\n");
}
}
return ;
}
2.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int t,a,b,c;
void pra()
{
puts("B");
}
void prb()
{
puts("G");
}
void prc()
{
puts("D");
}
void solve1()
{
if((a&)&&(b&))
prb();
else
pra();
}
void solve2()
{
if((a^b)!=) pra();
else prb();
}
void solve3()
{
a--;
b--;
if((a+b)%!=)
prc();
else
{
if(a<b) swap(a,b);
if(a==b) prb();
else if((a-b)==) pra(); //()
else prc();
}
}
void solve4()
{
a--;
b--;
if(a>b)
swap(a,b);
c=b-a;
if(a==int((sqrt()+)/*c))
prb();
else
pra();
}
int main()
{
cin>>t;
while(t--)
{
cin>>c>>a>>b;
if(c==) solve1();
else if(c==) solve2();
else if(c==) solve3();
else if(c==) solve4();
}
return ;
}
Life Winner Bo HDU - 5754的更多相关文章
- 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 5754Life Winner Bo
Life Winner Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 5754Life Winner Bo
给定一个n*m的矩阵,有四种棋子(国际象棋的王,王后,骑士,车).起点在(1,1)先走到(n,m)获胜. 分析:车是nim博弈.王后是威佐夫博弈.王和骑士写两个1000*1000的预处理即可. hdu ...
- 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/ ...
- 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种不 ...
随机推荐
- Docker 入门指南——Dockerfile 指令
COPY 复制文件 格式: COPY [--chown=<user>:<group>] <源路径>... <目标路径> 源路径可以是多个,甚至可以使通配 ...
- P4213 【模板】杜教筛(Sum)(杜教筛)
根据狄利克雷卷积的性质,可以在低于线性时间复杂度的情况下,求积性函数前缀和 公式 \[ 求\sum_{i=1}^{n}\mu(i) \] 因为\(\mu*I=\epsilon\) 所以设\(h=\mu ...
- Java基础 【Math、Random、System、BigInteger、BigDecimal、Date、Calendar等常用类的使用】
学习的这几个类 是日常工作中经常要使用到的类 Math 类包含用于执行基本数序运算的方法,如初等指数.对数.平方根和 三角函数. 成员方法 1.public static int abs(int a ...
- VirtuablBox 出错: VERR_SUPLIB_OWNER_NOT_ROOT 解决方法
刚刚把 VirtualBox 升级, 从 3.2 到 4.0.4 后,虚拟机上的系统无法运行, 提示: VERR_SUPLIB_OWNER_NOT_ROOT 查了一下,发现是因为 /opt 的 own ...
- JAVA中char和String/值类型和引用类型的区别
import java.util.*; class test { public static void main(String[] args) { char a[] = {'b', 'a', 'c'} ...
- 【测试工程师面试】面试官热衷询问的N个问题
1. 数据库中左连接右连接的区别 2.JAVA中continue和break的区别 3.Linux中查看某一个进程并且杀死 1.数据库中多表连接,根据不同的表的某一个字段进行关联, 左连接是将左边表全 ...
- 1. dubbo概述
dubbo简介: 官网:http://dubbo.io 最大程度进行解耦,降低系统耦合性,可以跨工程,跨项目; 生产者/消费者模式; jdk:1.6以上 maven:3.0以上 国际maven仓库:h ...
- Python统计list中各个元素出现的次数
来自:天蝎圣诞结 利用Python字典统计 利用Python的collection包下Counter类统计 利用Python的pandas包下的value_counts类统计 字典统计 a = [1, ...
- [原][数学][C++][osg]空间向量OA到转到空间向量OB、以及四元素Q1转到Q2的函数
注意:Oa其实在OK的延长线上,上图只是为了好看才把Oa和OK分开了 算法需求如图所示: 已知空间向量OA和空间向量OB 我想算出OA向OB按某角度或者某时间移动 变成空间向量Oa的算法 先说废话:我 ...
- JqueryValidate 表单验证插件
1.适用场景 表单 ( 支持自定义规则 ) 2.相关文章 jQuery Validate 3.实际问题 JqueryValidate表单相同Name不校验问题解决