HDU3951_Coin Game
Coin Game
Problem Description
一堆n个硬币围成一圈,两个人轮流拿走连续k个硬币,拿走最后一堆的人获胜
问你第一个人获胜还是第二个
思路:
这是NIM游戏改编版本
但是道理都一样,俗称模仿游戏
这里有一个特例,k==1的时候输赢已经确认了,因为此时,他们都不能改变自己拿的个数
k>1的时候,无论第一个怎么拿,第二个都能拿走若干个,并且使拿走之后的硬币成偶数堆,并且完全对称
举一个例子,如果n为奇数,那么第一个人拿了m个,第二个人只需要拿m-1就行了,能使之后的状态对称偶数堆
其他类似同理
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 1e5+100;
#define pr(x) cout << #x << " = " << x << " ";
#define prln(x) cout << #x << " = " << x <<endl;
typedef long long ll;
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
int n,k, kase =0;
int t;cin >> t;
while(t--) {
cin >> n >> k;
int ok = 0;
if(k == 1){
if(n&1) ok = 0;
else ok = 1;
} else {
if(k>=n) ok = 0;
else ok = 1;
}
if(ok == 1) printf("Case %d: second\n",++kase);
else if(ok == 0) printf("Case %d: first\n",++kase);
}
return 0;
}
浙公网安备 33010602011771号