2 shunfurh shunfurh 于 2017.01.05 00:27 提问

Game

问题描述 :

After played many kinds of nim games, Xay and Amr decided to play something different. As the judge, I wrote several valid pairs of numbers on the blackboard. For every pair (x, y), it is valid only if -y ≤ x ≤ y and the greatest common divisor of x and y is 1. The typical legal move is to alter just one of these pairs. If we change (x, y) to (a, b):
1. (a, b) should be a valid pair.
2. 1 ≤ b < y if y != 1
3. 1 ≤ b ≤ y, -b < a < b if y = 1.

Furthermore, such a replacement will be legal for Xay only if a*y – b*x < 0, legal for Amr only if a*y – b*x > 0.For example, Xay can change (2, 5) to (1,3), (1,4), (-1,2), (0,1), (-1,1), etc. And Amr can similarly change (2, 5) to (1, 2), (2, 3), (3, 4), (1, 1), etc.

They will play on these pairs alternately. The last one who be able to move is the winner .We have already knew that both Amr and Xay are very clever and they will play this game perfectly. Now, my dear programmers, can you predict that who will be the winner?

输入:

The first line contains a single positive integer T. which is the number of test cases. Each test case starts with a line with a single positive integer n(1 ≤ n ≤ 100) and a string “Xay” or “Amr” means who moves first. Then n lines follows, each line contains a pair of integers x and y. (1 ≤ y ≤ 15 and �y ≤ x ≤ y)
输出:

The first line contains a single positive integer T. which is the number of test cases. Each test case starts with a line with a single positive integer n(1 ≤ n ≤ 100) and a string “Xay” or “Amr” means who moves first. Then n lines follows, each line contains a pair of integers x and y. (1 ≤ y ≤ 15 and �y ≤ x ≤ y)
样例输入:

3
1 Xay
0 1
2 Amr
1 1
-1 1
2 Xay
1 4
-1 2
样例输出:

Amr
Xay
Amr

Hint

1个回答

caozhy
caozhy   Ds   Rxr 2017.01.12 00:47
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
Flip Game(状态压缩+BFS)
Link:http://poj.org/problem?id=1753 Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32393   Accepted: 14147 Description Flip game
LeetCode- 289. Game of Life - 思路详解-C++
假设有一个大小为m*n的板子,有m行,n列个细胞。每个细胞有一个初始的状态,死亡或者存活。每个细胞和它的邻居。垂直,水平以及对角线。按照规则互动,计算下一状态。
Jump Game II -- LeetCode
原题链接: http://oj.leetcode.com/problems/jump-game-ii/  这道题是Jump Game的扩展,区别是这道题不仅要看能不能到达终点,而且要求到达终点的最少步数。其实思路和Jump Game还是类似的,只是原来的全局最优现在要分成step步最优和step-1步最优(假设当前步数是step)。当走到超过step-1步最远的位置时,说明step-1不
Game AI Pro 3 Collected Wisdom of Game AI Professionals 无水印pdf
Game AI Pro 3 Collected Wisdom of Game AI Professionals 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
[Game Engine]开源游戏框架(转至wiki)
   Agar - 一个高级图形应用程序框架,用于2D和3D游戏。Allegro - 基于 C/C++ 的游戏引擎,支持图形,声音,输入,游戏时钟,浮点,压缩文件以及GUI。Axiom 引擎 - OGRE的衍生引擎。Baja 引擎 - 专业品质的图像引擎,用于The Lost Mansion。Boom - Doom代码的一部分。由TeamTNT开发Bui
2D Game Kit 1--Get Started
Unity新出的2D Game Kit现在可以免费在Assets Store下载了,支持2017.3以上的版本。该2D游戏套件可实现快速开发2D游戏,不用编程。接下来是Unity官方关于2D Game Kit的教程。----------------------------------------------------------1.创建场景命名好后点击 Create会生成如下资源:里面包括背景,...
CRC.Game.AI.Pro.3.Collected.Wisdom.of.Game.AI.Professionals.2017
CRC.Game.AI.Pro.3.Collected.Wisdom.of.Game.AI.Professionals.2017
codeforces 936B Sleepy Game
http://www.elijahqi.win/2018/02/26/codeforces-936b-sleepy-game/ Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edg...
Game Engine Architecture(中英两版本)
该书对游戏引擎包含渲染引擎、物理引擎、碰撞检测系统、音效、脚本引擎、电脑动画、人工智能、网络引擎以及场景管理进行详细深入的介绍。本资源是Game Engine Architecture(游戏引擎架构)设计的经典教材,在此为了方便大家学习,包含了中文与英文两个版本;给那些游戏引擎爱好者十足的学习提高自己的机会。
Game Engine Architecture 2nd Edition
刚刚出版的《Game Engine Architecture 2nd Edition》,太大了,分成两次上传