NC24606. [USACO 2011 Ope S]Cow Checkers
描述
输入描述
* 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
输出描述
* Lines 1..T: Should contain either 'Farmer John' or 'Bessie' depending on who wins each game.
示例1
输入:
3 3 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).C++14(g++5.4) 解法, 执行用时: 9ms, 内存消耗: 488K, 提交时间: 2020-03-07 18:25:59
#include <bits/stdc++.h> using namespace std; int main() { int n,m; scanf("%d%d",&n,&m); int t; cin >> t; int a,b; while(t--) { cin >> a >> b; if(a > b) swap(a,b); int k = floor((b-a)*((1.0+sqrt(5.0))/2.0)); if(k != a) cout<<"Bessie"<<endl; else cout<<"Farmer John"<<endl; } return 0; }
Python3 解法, 执行用时: 56ms, 内存消耗: 4636K, 提交时间: 2023-04-11 17:10:47
import math N, M = map(int, input().split()) T = int(input()) while T: x, y = map(int, input().split()) z = 0 if x > y: x, y = y, x tmp = int((y-x) * (math.sqrt(5) + 1) / 2) if tmp == x: print("Farmer John") else: print("Bessie") T -= 1
C++(clang++ 11.0.1) 解法, 执行用时: 6ms, 内存消耗: 468K, 提交时间: 2022-09-03 20:45:38
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c,d,e,t,n,m; cin>>n>>m>>t; while(t--) { cin>>a>>b; if(a>b) swap(a,b); if(a==int((b-a)*((sqrt(5.0) + 1) / 2))) cout<<"Farmer John"<<endl; else cout<<"Bessie"<<endl; } }