Codeforces Gym 101981 A Adrien and Austin

题意:一堆石头有N个,两个人轮流取,每人只能取1-K个石头,且取的石子必须是连续的K个,问谁赢?

分析:

1、K==1时,只与石子N的奇偶性有关,N为奇数先手赢,N为偶数后手赢。

2、N==0时,后手赢。

3、K>=2时,由于必须拿连续的K个,所以先手是有必胜策略的:即从石子最中间取走1或2颗石头,将石头分成数目相等的两堆,这样无论后手怎么取,先手只需在剩下的那堆石头模仿后手操作,就能保证必赢。

代码如下:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
typedef long long ll;
int N,K;
int main()
{
	ios::sync_with_stdio(false);
	cin>>N>>K;
	if(N==0){
		cout<<"Austin"<<endl;
		return 0;
	}
	if(K==1){
		if(N%2)
			cout<<"Adrien"<<endl;
		else
			cout<<"Austin"<<endl;
		return 0;
	}
	if(N<=K){
		cout<<"Adrien"<<endl;
		return 0;
	}
	if(K>=2)
		cout<<"Adrien"<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/zsnowwolfy/article/details/90040143