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 ...
随机推荐
- Linux 内核同步之自旋锁与信号量的异同【转】
转自:http://blog.csdn.net/liuxd3000/article/details/8567070 Linux 设备驱动中必须解决的一个问题是多个进程对共享资源的并发访问,并发访问会导 ...
- Linux网络编程之套接字基础
1.套接字的基本结构 struct sockaddr 这个结构用来存储套接字地址. 数据定义: struct sockaddr { unsigned short sa_family; /* addre ...
- android CVE 漏洞汇总
arm exploits 技术教程: Learning Pentesting for Android Devices CVE-2015-1530 ,CVE-2015-1474 两个android整数溢 ...
- linux内核启动分析(2)
-----以下内容为从网络上整理所得------ 主要介绍kernel_init线程(函数),这个线程在rest_init函数中被创建,kernel_init函数将完成设备驱动程序的初始化,并调用in ...
- scrapy抓取学院新闻报告
抓取四川大学公共管理学院官网(http://ggglxy.scu.edu.cn)所有的新闻咨询. 实验流程 1.确定抓取目标.2.制定抓取规则.3.'编写/调试'抓取规则.4.获得抓取数据 1.确定抓 ...
- [New learn]@class和#import的区别使用
1.简介 我们在查看代码的时候经常会发现有些地方使用@class而有些地方使用#import,他们到底有什么区别呢, 本文意图去归纳和总结这两种类引用的是的处理方法和规则. 2.分析 此小节会通过一些 ...
- 理解rest架构
越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件"采用客户端/服务器模式,建立在分布式体系上,通过互联网通信,具有高延时(high latency).高 ...
- hive-group by的时候把两个字段变成map
源表结构: pcgid string mobilegid string value double 测试数据如下: p1 m1 ...
- Convolutional Neural Networks卷积神经网络
转自:http://blog.csdn.net/zouxy09/article/details/8781543 9.5.Convolutional Neural Networks卷积神经网络 卷积神经 ...
- hdu多校5
1002 思路:贪心显然不好贪,直接爆搜. #include<bits/stdc++.h> #define LL long long #define fi first #define se ...