题目描述

One day, Bessie decides to challenge Farmer John to a game of ‘Cow Checkers’. The game is played on an M*N (1 <= M <= 1,000,000; 1 <= N <= 1,000,000) checkerboard that initially contains a single checker piece on the checkboard square coordinates (X, Y) (0 <= X < M; 0 <= Y < N). The bottom leftmost square of the checkerboard has

coordinates (0, 0), and the top rightmost square has coordinates (M-1, N-1). Bessie always moves first, and then the two players alternate turns. Each turn comprises one of three types of moves:

1) Move the checker piece to any square on the same row to the left of its current position.

2) Move the checker piece to any square on the same column below its current position.

3) Move the checker piece to any spot k squares below and k squares to the left of the current square (where k is any positive integer such that this new spot is still on the checkerboard).

The first player unable to make a move (i.e., because the checker is at (0, 0)) loses. Given that Bessie always goes first, determine who will win the game if both play optimally.

Play and report the winner for T games (1 <= T <= 1,000) reading in a new X,Y starting value for each new game.

有一天,Bessie准备玩一个叫做奶牛跳棋的游戏,来挑战Farmer John。

这个游戏的棋盘大小为 M*N (1 <= M <= 1,000,000; 1 <= N <= 1,000,000) 。最初棋盘上只有一个棋子在(x,y),棋盘的左下角坐标是(0,0),右上角的坐标是(M-1,N-1)。

每次游戏Bessie都是第一个开始,之后两个人轮流。

每次下棋的时候都有三种走法:

1.向左走任意步

2.向下走任意步

3.向左走k步然后向下走k步(k可随便取值,只要不走出棋盘)

先走到(0,0)的人就算输。

游戏共有T次,每次都会给出一个新的坐标(x,y),请输出每一轮赢家的名字。
输入输出格式
输入格式:

  • Line 1: Two space-separated integers: M and N

  • Line 2: A single integer: T

  • Lines 3..T+2: Two space-separated integers: X and Y

第一行:M N

第二行:T

第三行到第T+2行:这一轮的X Y

输出格式:

  • Lines 1..T: Should contain either ‘Farmer John’ or ‘Bessie’ depending on who wins each game.

共T行,每一行输出那一轮的赢家

输入输出样例
输入样例#1:

3 3
1
1 1

输出样例#1:

Bessie

说明

Farmer John and Bessie are playing one game on a 3*3 checkerboard with the checker piece initially at (1, 1) (i.e. at the center of the board).

Bessie initially can only move the checker piece to either (1, 0) or (0, 1), or (0, 0). Bessie can immediately win by moving the piece to (0, 0).

起点在(1,1),一开始有三种选择(1,0),(0,1),(0,0)只要Bessie在开始时将棋子移到(1,0)或(0,1),就必胜无疑。

感谢@ 2014nhc 提供的翻译

解题思路

威佐夫博弈裸题。。。两堆石子,一堆n个,一堆m个

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath> using namespace std; int n,m,T; int main(){
scanf("%d%d%d",&n,&m,&T);
while(T--){
int x,y;
scanf("%d%d",&x,&y);
if(x>y) swap(x,y);
int tmp=floor((y-x)*(sqrt(5)+1)/2);
if(tmp==x) cout<<"Farmer John"<<endl;
else cout<<"Bessie"<<endl;
}
return 0;
}

最新文章

  1. javascript-组合模式
  2. 开始学emacs-1
  3. Asp.net Core WebApi 支持json/xml格式的数据返回
  4. Python mix-in 组合 ~ 将类组合起来 .
  5. 阅读《构建之法》第八、九、十章有感和Sprint总结
  6. cookie、localStorage、sessionStorage之间的区别
  7. WORDPRESS开发(一)自定义页面显示分类目录
  8. 修改ORACLE的语言参数
  9. 深入学习sea.js
  10. WiFi天线分集
  11. GraphX PageRank
  12. vue项目中遇到的那些事。
  13. SQL语句练习题【主供自己学习、记忆】
  14. JMeter—总结
  15. pythonweb服务器编程(三)
  16. 分析轮子(七)- RandomAccess.java
  17. 使用SURF::create()以后报错无法解析
  18. [原]Jenkins(十四)---jenkins示例:admin管理所有项目,新建用户只能看部分项目
  19. 猫眼电影爬取(三):requests+pyquery,并将数据存储到mysql数据库
  20. margin 和 padding

热门文章

  1. Java监控工具介绍,VisualVm ,JProfiler,Perfino,Yourkit,Perf4J,JProbe,Java微基准测试【转】
  2. TF坐标变换
  3. NFS+mou
  4. Java写爬虫代码时报org.apache.http.client.ClientProtocolException: URI does not specify a valid host异常的处理
  5. 事件处理器v-on:(event)/@(event)
  6. 使用Java代码获取Java进程ID的方法
  7. 用docker部署zabbix
  8. linux下安装rabbitmq 集群
  9. LinkedList集合 实现栈和队列
  10. css3之2D 转换