Problem Statement

Takahashi and Aoki are playing a stone-taking game. Initially, there are N piles of stones, and the i-th pile contains Ai stones and has an associated integer Ki.

Starting from Takahashi, Takahashi and Aoki take alternate turns to perform the following operation:

  • Choose a pile. If the i-th pile is selected and there are X stones left in the pile, remove some number of stones between 1 and floor(XKi) (inclusive) from the pile.

The player who first becomes unable to perform the operation loses the game. Assuming that both players play optimally, determine the winner of the game. Here, floor(x) represents the largest integer not greater than x.

Constraints

  • 1≤N≤200
  • 1≤Ai,Ki≤109
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A1 K1
:
AN KN

Output

If Takahashi will win, print Takahashi; if Aoki will win, print Aoki.

Sample Input 1

2
5 2
3 3

Sample Output 1

Aoki

Initially, from the first pile at most floor(5⁄2)=2 stones can be removed at a time, and from the second pile at most floor(3⁄3)=1 stone can be removed at a time.

  • If Takahashi first takes two stones from the first pile, from the first pile at most floor(3⁄2)=1 stone can now be removed at a time, and from the second pile at most floor(3⁄3)=1 stone can be removed at a time.
  • Then, if Aoki takes one stone from the second pile, from the first pile at most floor(3⁄2)=1 stone can be removed at a time, and from the second pile no more stones can be removed (since floor(2⁄3)=0).
  • Then, if Takahashi takes one stone from the first pile, from the first pile at most floor(2⁄2)=1 stone can now be removed at a time, and from the second pile no more stones can be removed.
  • Then, if Aoki takes one stone from the first pile, from the first pile at most floor(1⁄2)=0 stones can now be removed at a time, and from the second pile no more stones can be removed.

No more operation can be performed, thus Aoki wins. If Takahashi plays differently, Aoki can also win by play accordingly.

Sample Input 2

3
3 2
4 3
5 1

Sample Output 2

Takahashi

Sample Input 3

3
28 3
16 4
19 2

Sample Output 3

Aoki

Sample Input 4

4
3141 59
26535 897
93 23
8462 64

Sample Output 4

Takahashi

    这种题只能打表找规律啊QWQ
把k<=10,n<=30的sg函数打表出来,找了找规律,发现:
sg(x) = ( x%k==0 ? x/k : sg(x - x/k - 1) ) 当k比较小的时候,显然 x - x/k -1 的减小速率是非常快的,大致和k同阶(可能略大一点);
当k比较大的时候,可以发现在减小的过程中很多x/k都是一样的,并且一样的都是连续的,所以我们对于 x/k == i 可以计算出 x'/k 第一次 <i 的x'是哪个,因为x/k没减小1x减小的幅度大致是和k同阶的,所以总的复杂度就大致和 x/k同阶。。 因为不管k比较大还是比较小我们都可以连续一段处理,所以算一个sg函数的复杂度就是 min ( k , x/k ),大概是1e5级别的。。。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=205; int n,A,k,Xor; inline int Get(int x){
if(x<k) return 0;
if(x%k==0) return x/k;
int der=x/k+1,lef=x%k;
if(der>=lef) return Get(x-der);
else return Get(x-lef/der*der);
} int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&A,&k);
Xor^=Get(A);
} if(Xor) puts("Takahashi");
else puts("Aoki"); return 0;
}

AtCoder - 3939 Strange Nim的更多相关文章

  1. AtCoder练习

    1. 3721 Smuggling Marbles 大意: 给定$n+1$节点树, $0$为根节点, 初始在一些节点放一个石子, 然后按顺序进行如下操作. 若$0$节点有石子, 则移入盒子 所有石子移 ...

  2. 【AtCoder】ARC091

    C - Flip,Flip, and Flip...... 只有一个这一个是反面 只有一行那么除了两边以外都是反面 否则输出\((N - 2)*(M - 2)\) #include <bits/ ...

  3. sg函数小结

    sg函数小结 sg函数是处理博弈问题的重要工具. 我们知道sg(x)=mex{sg(j)|x能到达状态j} sg(x)=0时代表后手赢,否则先手赢. 对于一个问题,如果某些子问题是相互独立的,我们就可 ...

  4. Atcoder #017 agc017 D.Game on Tree 树上NIM 博弈

    LINK 题意:树上NIM的模板题,给出一颗树,现有操作删去端点不为根节点的边,其另一端节点都将被移除,不能取者为败 思路:一看就是个NIM博弈题,只是搬到树上进行,树上DFS进行异或 记得#014D ...

  5. Atcoder #014 agc014_D 树形DP+nim变形

    LINK 题意:两人在一颗树上做游戏,先手可以将树上一个节点染白,后手染黑,到最后时,所有与黑色相邻的白色同时变黑.如果还存在白色,先手胜,否则后手胜. 思路:首先不考虑树上,单独为链时,不管找规律也 ...

  6. LeetCode 292. Nim Game

    Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...

  7. Atcoder Grand-014 Writeup

    A - Cookie Exchanges 题面 Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respec ...

  8. AtCoder Grand Contest 014

    AtCoder Grand Contest 014 A - Cookie Exchanges 有三个人,分别有\(A,B,C\)块饼干,每次每个人都会把自己的饼干分成相等的两份然后给其他两个人.当其中 ...

  9. AtCoder Beginner Contest 172 题解

    AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...

随机推荐

  1. 【BZOJ】1270 [BeijingWc2008]雷涛的小猫

    [算法]DP [题解]f1[i]表示第i棵树当前高度能得到的最多果子数 f2[i]表示高度i能得到的最多果子数. 于是有: f1[j]=max(f1[j],f2[i+delta])+mp[j][i]; ...

  2. 【BZOJ】1385 [Baltic2000]Division expression

    [算法]欧几里德算法 [题解]紫书原题 #include<cstdio> #include<algorithm> using namespace std; ; int T,t, ...

  3. idea 导入 java json 包

    1.java 项目导包 找到 External Libraries 下面的java版本包,在点击鼠标右键.直接找到jar路径全部选中导入即可.

  4. js按值及引用传递中遇到的小问题

    有人闲的蛋疼,非要在函数中使用如下方式传值,尼玛一下把我搞糊涂了.于是决定发挥打破沙锅问到底的精神搞清楚它. var a = 1,b = [], c = {}; function f(a, b, c) ...

  5. E题hdu 1425 sort

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 sort Time Limit: 6000/1000 MS (Java/Others)    M ...

  6. linux系统下git使用

    转载:http://www.cnblogs.com/bear2flymoon/p/4335364.html?ADUIN=563508762&ADSESSION=1430887070&A ...

  7. gpio子系统和pinctrl子系统(中)

    pinctrl子系统核心实现分析 pinctrl子系统的内容在drivers/pinctrl文件夹下,主要文件有(建议先看看pinctrl内核文档Documentation/pinctrl.txt): ...

  8. HDU 5118 GRE Words Once More!

    题目链接:HDU-5118 题意:给定一个有向无环图,每条边有一个权值.标定一些特定节点为“特殊节点”.从节点1出发到某“特殊节点”结束的路径,称为一个“GRE单词”.单词由路径上的权值组成.给定一组 ...

  9. C#.Net实体代码生成工具(EntitysCodeGenerate)的使用及.NET中的ORM实现

    1 引言 目前大多数项目或产品都使用关系型数据库实现业务数据的存储,这样在开发过程中,常常有一些业务逻辑需要直接用写SQL语句实现,但这样开发的结果是:遍地布满SQL语句.这些藕合较高的SQL语句给系 ...

  10. 获取分组后的TOP 1和TOP N记录

    MySQL获取分组后的TOP 1和TOP N记录 有时会碰到一些需求,查询分组后的最大值,最小值所在的整行记录或者分组后的top n行的记录,在一些别的数据库可能有窗口函数可以方面的查出来,但是MyS ...