B - Road to Arabellahttps://vjudge.csgrandeur.cn/problem/Gym-102263B
Ayoub and Kilani felt board while they are going to ArabellaCPC in (Amman-Irbid) road, so Kilani invented a new game to play with Ayoub.
The game is described by the following rules :
Ayoub picks a random integer nn (1≤n≤109)(1≤n≤109) , and Kilani picks a random integer kk (1≤k≤n)(1≤k≤n), then they will start playing. In each turn a player can choose any number xx (1≤x≤max(1,m−k))(1≤x≤max(1,m−k)) (which mm is the current value of nn) and subtract it from nn. if nn equals zero then the player can't make a move. The player who can't make a move is considered to lose the game.
If Kilani starts, and each player played optimally, who would be the winner?
Input
First line of input contains integer TT (1≤T≤104)(1≤T≤104) the number of test cases.
Each one of next TT lines contains two integers nn and kk, (1≤k≤n≤109)(1≤k≤n≤109).
Output
print "Kilani" if he wins, and print "Ayoub" otherwise. (the output is case sensitive)
Example
input
Copy
2 2 1 4 1
output
Copy
Ayoub Kilani
#include<bits/stdc++.h>
using namespace std;
int T;
int main(){
scanf("%d",&T);
while (T--)
{
int n,m;
bool flag;
scanf("%d%d",&n,&m);
if(m>=n-1){
if(n%2==0) flag=false;
else flag=true;
}
else flag=true;
if(flag)
cout << "Kilani" << endl;
else
cout << "Ayoub"<<endl;
}
}
题解:
当只能选择1的时候是能确定胜负局面的时候。假如k==n或k==n−1,则一开始就确定了胜负,n偶Kilani负,n奇Kilani胜。假如k<n-1,Kilani先手,可以选择一个数使m为偶数,且之后的回合都只能选1,必胜。