Gym101147A sg函数
来源:互联网 发布:电影没字幕翻译软件 编辑:程序博客网 时间:2024/05/21 06:56
Faheem and Faheema love to play what they call the game of Osho, in this game they choose a number N randomly, the first player subtracts a non-zero number Bk1 less than or equal to N from N, then the second player subtracts number Bk2 (where B is given and ki is a non negative integer number), then again the first and so on until one of the players loses when he/she can’t make any move. In other words, when it’s a player’s turn and N equals 0. For example let’s see this game when B=2 and N=3. The first player Faheem can subtract 1 or 2 the optimal move here is 1, N now equals 2. In her turn Faheema subtract 2 because 1 will make Faheem win, Faheem now can’t play any move and he loses.
After a while they found that this game is boring so they decided to upgrade it, their version combines multiple subgames of the form (Bi, Ni) and the player can choose which of them he wants to play his move in, a player loses when he/she can’t make a move.
Given the subgames, your job is to determine which player wins the whole game assuming that both players play optimally.
Input
The first line contains T, the number of test cases. The next T lines contain G (1 ≤ G ≤ 100) the number of subgames and then follows G pairs of integers (1 ≤ Bi, Ni ≤ 1, 000, 000, 000) describing each subgame.
Output
For each test case print 1 if the first player wins the game, or 2 if the second wins.
Examples
input
3
1 2 3
1 7 3
2 6 11 3 2
output
2
1
2
#include <iostream>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <map>#define MST(s,q) memset(s,q,sizeof(s))#define INF 0x3f3f3f3f#define MAXN 50005#define Lchild id<<1#define Rchild (id<<1)+1inline int lowbit(int x) {return x & (-x);}using namespace std;int get(long long a, long long b) { // sg if (b == 0) return 0; if ((b + 1) % (a + 1) == 0) return a % 2 == 0 ? 2 : 1; int c = b % (a + 1); return c % 2;}int main() { freopen("powers.in", "r", stdin); int T, n; long long a, b; cin >> T; while (T--) { scanf("%d", &n); int ans = 0; while (n--) { scanf("%I64d%I64d", &a, &b); ans ^= get(a, b); } if (ans == 0) printf("2\n"); else printf("1\n"); }}
- Gym101147A sg函数
- sg函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- sg函数
- SG函数
- SG函数
- SG函数
- sg函数
- SG函数
- SG函数
- Thinking in Java
- 一个测试中用到的小程序
- 如何访问 Google?使用VPN解锁
- 461. Hamming Distance
- 开篇喂各路神仙
- Gym101147A sg函数
- jAVA8 十大新特性
- C++模板类&适配器
- 十三、Mysql 分组函数/聚合函数/多行处理函数
- Baby Q PK小冰 谁才是QQ6.7新增的QQ群聊机器人之王 ...
- 【Java】System类
- 树莓派3 B+的引脚图
- Python 学习成长记(一)---- 甩掉你的包袱
- Training a logistic regression model with scikit-learn