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

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
/* ***********************************************
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 ;
}

找规律。皇后的时候转换成博弈

“有两堆石子,每次可以在一堆里取任意(非空)颗(相当于是车的走法),或者在两堆里取相同(非空)颗(相当于是象的走法),取到最后一颗石子的人获胜,问先后手谁有必胜策略。”

最新文章

  1. Docker Volume 之权限管理(转)
  2. 期待已久的2013年度最佳 jQuery 插件揭晓
  3. BZOJ1493 [NOI2007]项链工厂
  4. java中 ==与equals 有什么区别?
  5. CSS3绘制旋转的太极图案(一)
  6. cf 61 E. Enemy is weak 离散化+树状数组
  7. JAVA虚拟机学习笔记(一)Windows10下编译OpenJDK8
  8. (转载)PHP解析URL并得到URL中的参数
  9. HDOJ 1312 (POJ 1979) Red and Black
  10. IE下判断IE版本的语句
  11. MySQL安全问题
  12. [ios-必看] WWDC 2013 Session笔记 - iOS7中的多任务【转】
  13. [转载] Java中动态加载jar文件和class文件
  14. Jenkins持续集成演示
  15. Linux进程启动过程分析do_execve(可执行程序的加载和运行)---Linux进程的管理与调度(十一)
  16. python保存文件到数据库
  17. Zabbix监控系统部署:基本功能测试
  18. php 多进程
  19. ZooKeeper系列 (4) 构建ZooKeeper应用
  20. PmException--- SQL(统计报表)

热门文章

  1. 如何HTML标签和JS中设置CSS3 var变量
  2. Qt的widget与Button添加图片
  3. 零基础入门学习Python(32)--异常处理:你不可能总是对的
  4. Python之微信-微信机器人
  5. 一个关于vue+mysql+express的全栈项目(二)------ 前端构建
  6. python 调用 C 动态库
  7. noi.ac NOIP2018 全国热身赛 第二场 T3 color
  8. java 编码乱码问题
  9. this关键字的由来及使用
  10. HDU 2442