给出 a,b , 每个人 可以 将 大的数 可以减去 小的数的倍数,但不能变成负的, 谁先出现 x ,0 的状态 谁赢。
假设 当前可以选择的倍数k 是大于2 的, 那么这个状态就是必胜的。 a,b 转化成 b ,a%b 时, 若b, a%b 是必胜, 只要转化成 a%b+b , b 这个状态。
若 b,a%b 必败, 则 直接转化成 b ,a%b 。
那么 决定先手胜负的就是, 开始的 1 的个数, 因为 当 a, b 只有一种选择时 ,状态只有一种转移,谁先转化到偶数 或者谁先到最有一步,谁赢。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <assert.h>
#include <queue>
#define REP(i,n) for(int i=0;i<n;i++)
#define TR(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define ALLL(x) x.begin(),x.end()
#define SORT(x) sort(ALLL(x))
#define CLEAR(x) memset(x,0,sizeof(x))
#define FILLL(x,c) memset(x,c,sizeof(x))
using namespace std;
const double EPS = 1e-8;
#define LL long long
#define pb push_back
int a,b;
;
int tot;
int num[100];
int gcd(int a,int b){
if(b==0)return a;
if(a>=b){
int t = a/b;
tot ++ ;
num[tot] =t;
}
return gcd(b,a%b);
}
int main(){
while(scanf("%d%d",&a,&b),a|b){
tot= 0 ;
gcd(a,b);
int ans= 0;
int st =0;
for(int i=1;i<tot;i++){
//if(num[i]>1)ans ++;
if(!st && num[i]>1){
st = i;
break;
}else if(!st){
ans ++;
}
}
if(ans&1){
puts("Ollie wins");
}else{
puts("Stan wins");
}
}
return 0;
}
本文深入探讨了基于数与倍数减法的游戏策略,揭示了通过分析初始数的1的个数来预测先手胜负的规律。详细介绍了算法实现过程,包括使用C++编程语言的数学函数进行复杂状态转移的优化。
1104

被折叠的 条评论
为什么被折叠?



