博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder - 3939 Strange Nim
阅读量:5066 次
发布时间:2019-06-12

本文共 2819 字,大约阅读时间需要 9 分钟。

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:

NA1 K1:AN KN
Output

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

Sample Input 1
25 23 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
33 24 35 1
Sample Output 2
Takahashi
Sample Input 3
328 316 419 2
Sample Output 3
Aoki
Sample Input 4
43141 5926535 89793 238462 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 第一次 
#include
#define ll long longusing namespace std;const int N=205;int n,A,k,Xor;inline int Get(int x){ if(x
=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;}

 

 

转载于:https://www.cnblogs.com/JYYHH/p/9248543.html

你可能感兴趣的文章
jq 杂
查看>>
jquery datagrid 后台获取datatable处理成正确的json字符串
查看>>
作业一
查看>>
AJAX
查看>>
ActiveMQ与spring整合
查看>>
web服务器
查看>>
Git的使用--打tag
查看>>
F# 编程 借助 F# 构建 MVVM 应用程序
查看>>
ACFUN切换代码自用。。。
查看>>
网卡流量检测.py
查看>>
【转】Android的权限permission
查看>>
ajax
查看>>
poj1981 Circle and Points 单位圆覆盖问题
查看>>
POP的Stroke动画
查看>>
线程同步机制初识 【转载】
查看>>
Oracle 游标使用全解
查看>>
SQL语句在查询分析器中可以执行,代码中不能执行
查看>>
yii 1.x 添加 rules 验证url数组
查看>>
html+css 布局篇
查看>>
银行排队问题(详解队列)
查看>>