• AtCoder


    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
    • 1N200
    • 1Ai,Ki109
    • 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(52)=2 stones can be removed at a time, and from the second pile at most floor(33)=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(32)=1 stone can now be removed at a time, and from the second pile at most floor(33)=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(32)=1 stone can be removed at a time, and from the second pile no more stones can be removed (since floor(23)=0).
    • Then, if Takahashi takes one stone from the first pile, from the first pile at most floor(22)=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(12)=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;
    }
    


  • 相关阅读:
    0X01 OWASP WebGoat Splitting
    subprocess
    Python中getopt()函数的使用
    Python3_UDP客户端
    Python3编写TCP客户端
    Python3---pymysql库____操作数据库
    review——database (1)CH8-Relational Database Design
    删除的review——数据库 (1)CH6关系数据理论
    review——C# (15)转换
    review——C# (14)接口
  • 原文地址:https://www.cnblogs.com/JYYHH/p/9248543.html
Copyright © 2020-2023  润新知