LUOGU P3024 [USACO11OPEN]奶牛跳棋Cow Checkers
题目描述
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;
}
LUOGU P3024 [USACO11OPEN]奶牛跳棋Cow Checkers的更多相关文章
- [USACO11OPEN]奶牛跳棋Cow Checkers(博弈论)
题目描述 One day, Bessie decides to challenge Farmer John to a game of 'Cow Checkers'. The game is playe ...
- 3298: [USACO 2011Open]cow checkers
3298: [USACO 2011Open]cow checkers Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 65 Solved: 26[Su ...
- BZOJ3298: [USACO 2011Open]cow checkers(佐威夫博弈)
3298: [USACO 2011Open]cow checkers Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 195 Solved: 96[S ...
- bzoj 3298: [USACO 2011Open]cow checkers -- 数学
3298: [USACO 2011Open]cow checkers Time Limit: 10 Sec Memory Limit: 128 MB Description 一天,Besssie准备 ...
- 洛谷P1472 奶牛家谱 Cow Pedigrees
P1472 奶牛家谱 Cow Pedigrees 102通过 193提交 题目提供者该用户不存在 标签USACO 难度普及+/提高 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 农民约翰准备 ...
- BZOJ3298[USACO 2011Open]cow checkers——威佐夫博弈
题目描述 一天,Besssie准备和FJ挑战奶牛跳棋游戏.这个游戏上在一个M*N的棋盘上, 这个棋盘上在(x,y)(0<=x棋盘的左下角是(0,0)坐标,棋盘的右上角是坐标(M-1,N-1). ...
- BZOJ3298: [USACO 2011Open]cow checkers 威佐夫博弈
Description 一天,Besssie准备和FJ挑战奶牛跳棋游戏.这个游戏上在一个M*N的棋盘上, 这个棋盘上在(x,y)(0<=x棋盘的左下角是(0,0)坐标,棋盘的右上角是坐标(M-1 ...
- Luogu P2419 [USACO08JAN]牛大赛Cow Contest
题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a p ...
- luogu P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
随机推荐
- 解决jquery ajax在跨域访问post请求的时候,ie9以下无效(包括ie9)的问题
最近在做项目的时候遇到一个问题,就是跨域请求ajax的时候ie9以下的浏览器不可以访问,直接执行error里面的代码,但是也不报错,就上网查了查,发现了一个很好用的方法,在这里记录一下,也希望可以帮到 ...
- HDU3480 Division——四边形不等式或斜率优化
题目大意 将N个数分成M部分,使每部分的最大值与最小值平方差的和最小. 思路 首先肯定要将数列排序,每部分一定是取连续的一段,于是就有了方程 $\Large f(i,j)=min(f(i-1,k-1) ...
- C++: inheritance
公有继承(public).私有继承(private).保护继承(protected)是常用的三种继承方式. 1. 公有继承(public) 公有继承的特点是基类的公有成员和保护成员作为派生类的成员时, ...
- scoreboarding
Reference docs: https://en.wikipedia.org/wiki/Scoreboarding SSC_course_5_Scoreboard_ex.pdf 1, what i ...
- 关于str的打印格式
实际上一般的打印格式应该是这样的: %[(keyname)][flags][width][.precision]typecode (1) keyname: 用于打印Dict类型时做索引; (2) fl ...
- 容斥原理——poj1091
将m质因子分解,然后枚举选取的质因子个数i进行容斥,每种情况进行一次dfs即可 dfs结束标记:当质因子个数达到i时退出递归,同时累加该解对应的方案数 /* 给定n,m 共有n个数的数组a,不超过m ...
- go语言基本运算符
go语言基本运算符 1.算术运算符 以下假设A=10,B=20: 2.关系运算符 以下假设A=10,B=20: 3.逻辑运算符 以下假设A=true,B=false: 4.位运算符 十进制转二进制: ...
- maven 工程搭建
使用Maven建立一个Quite start 项目 2.命名卫 bhz-parent 3.groupid 为: bhz 4.artifactId 为: bhz-parent package:为空不填 ...
- 转:进程上下文VS中断上下文
源地址:http://www.cnblogs.com/zzx1045917067/archive/2012/12/19/2824552.html 内核空间和用户空间是现代操作系统的两种工作模式,内核模 ...
- java生成excel报表文件
此次简单的操作将数据从数据库导出生成excel报表以及将excel数据导入数据库 首先建立数据库的连接池: package jdbc; import java.io.FileInputStream; ...