Codeforces Round #114 (Div. 1) C. Wizards and Numbers 博弈论
C. Wizards and Numbers
题目连接:
http://codeforces.com/problemset/problem/167/C
Description
In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:
Replace b with b - ak. Number k can be chosen by the player, considering the limitations that k > 0 and b - ak ≥ 0. Number k is chosen independently each time an active player casts a spell.
Replace b with b mod a.
If a > b, similar moves are possible.
If at least one of the numbers equals zero, a player can't make a move, because taking a remainder modulo zero is considered somewhat uncivilized, and it is far too boring to subtract a zero. The player who cannot make a move, loses.
To perform well in the magic totalizator, you need to learn to quickly determine which player wins, if both wizards play optimally: the one that moves first or the one that moves second.
Input
The first line contains a single integer t — the number of input data sets (1 ≤ t ≤ 104). Each of the next t lines contains two integers a, b (0 ≤ a, b ≤ 1018). The numbers are separated by a space.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output
For any of the t input sets print "First" (without the quotes) if the player who moves first wins. Print "Second" (without the quotes) if the player who moves second wins. Print the answers to different data sets on different lines in the order in which they are given in the input.
Sample Input
4
10 21
31 10
0 1
10 30
Sample Output
First
Second
Second
First
Hint
题意
中文题面见:http://acm.uestc.edu.cn/#/problem/show/1169
题解:

代码
#include<bits/stdc++.h>
using namespace std;
int check(long long a,long long b)
{
if(a==0)return 0;
if(check(b%a,a))
{
b/=a;
return !((b%(a+1))&1);
}
return 1;
}
int main()
{
int t;scanf("%d",&t);
while(t--)
{
long long a,b;
cin>>a>>b;
if(a>b)swap(a,b);
if(check(a,b))cout<<"First"<<endl;
else cout<<"Second"<<endl;
}
}
Codeforces Round #114 (Div. 1) C. Wizards and Numbers 博弈论的更多相关文章
- Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize 概率dp
B. Wizards and Huge Prize Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题
A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #114 (Div. 1) D. Wizards and Roads 笛卡尔树+树贪心+阅读题
D. Wizards and Roads 题目连接: http://www.codeforces.com/contest/167/problem/D Description In some count ...
- Codeforces Round #114 (Div. 1) E. Wizards and Bets 高斯消元
E. Wizards and Bets 题目连接: http://www.codeforces.com/contest/167/problem/E Description In some countr ...
- Codeforces Round #114 (Div. 2)
Codeforces Round #114 (Div. 2) 代码 Codeforces Round #114 (Div. 2) C. Wizards and Trolleybuses 思路 每条车的 ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers(如压力dp)
Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standard i ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers 状压dp+数位dp
题目链接: http://codeforces.com/problemset/problem/401/D D. Roman and Numbers time limit per test4 secon ...
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...
随机推荐
- python写一段脚本代码自动完成输入(目录下的所有)文件的数据替换(修改数据和替换数据都是输入的)【转】
转自:http://blog.csdn.net/lixiaojie1012/article/details/23628129 初次尝试python语言,感觉用着真舒服,简单明了,库函数一调用就OK了 ...
- C语言的小括号----其实是逗号运算符
比如下面的代码: #include <stdio.h> void fun() { int a, b, c, d; a = (, b = ); c = (, ); d = (, ); pri ...
- C基础 寻找随机函数的G点
引言 随机函数算法应该是计算机史上最重要的十大算法之一吧. 而C中使用的随机函数 #include <stdlib.h> _Check_return_ _ACRTIMP int __cde ...
- Socket与URL通信比较
转至链接:http://blog.csdn.net/qq_15848173/article/details/46328399 利用URL通信和Socket进行通信有很多相似之处.他们都是利用建立连接. ...
- Shell三剑客之sed命令
Sed简介 Sed是Stream Editor(流编辑器)缩写,是操作.过滤和转换文本内容的强大工具,常用功能有增删改查. Sed命令执行流程 Sed语法格式 Sed [option] ‘[匹配][处 ...
- FineReport——JS二次开发(下拉框)
下拉框显示多列时,输入的内容检索的内容为显示值整行数据,而不是实际值. 下拉框选择之后,控件显示的是显示值而非实际值. 对于下拉框显示队列,可以有多种方法,但是经过测试大多数方法不适用,检索效率太低, ...
- spring mvc3+默认首页设置问题
web.xml配置: <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-patte ...
- 共享变量 static
一个类,有static变量counter,所有类实例共享 如果多个类实例,通过多线程访问static变量,就会产生覆盖的情况. 会发现counter偏小. 解决方法: AtomicLong count ...
- js字符串与Unicode编码互相转换
).toString() "597d" 这段代码的意思是,把字符'好'转化成Unicode编码,toString()就是把字符转化成16进制了 看看charCodeAt()是怎么个 ...
- 一、python基础相关知识体系
python基础 a. Python(解释型语言.弱类型语言)和其他语言的区别? 一.编译型语言:一次性,将全部的程序编译成二进制文件,然后在运行.(c,c++ ,go) 运行速度快.开发效率低 二. ...