https://www.luogu.org/problem/show?pid=1290
分析:
在原网站就有题解的 跑来看坑定是没看明白站内题解了 这也是水过而已
题目中说 完美的操作 我理解就是尽量让自己赢 也就是创造机会让自己赢 那到底怎样才能创造机会让自己赢呢
这里有三种情况 设给定的两个数字分别为 a ,b (a>=b)
1、a%b==0 谁面临这种情况谁就赢了
2、a<2*b 面临这种情况没有什么好挑的 只能用 a - b
3、a>2*b 这中情况就比较有意思了 当一个人面对这种情况时他就有了多种选择 因为他可以减去b的整数倍嘛 在这多种选择的情况下 某些选择最终会使他输掉而某些选择最终会使他赢 那到底该怎么选择是个很纠结的问题 一步走错满盘皆输嘛 但是我们不必纠结 因为题目中说 完美的操作 也就是说他会选择使自己赢的方法至于具体怎么选 我们就不用关心了 所以 谁面对这种情况 谁也就是赢的
AC代码:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include<list>
#include <bitset>
#include <climits>
#include <algorithm>
#define gcd(a,b) __gcd(a,b)
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
typedef long long LL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
using namespace std;
int sum;
int flag;
void solve(LL a,LL b){
if (flag) return;
if(a<b) swap(a,b);
if (a%b==0||a>2*b){
flag=1,sum++;
return;
}
sum++;solve(a-b,b);
}
int main (){
int t;
scanf ("%d",&t);
while (t--){
LL a,b;
scanf ("%lld%lld",&a,&b);
sum=0;flag=0;
solve(a,b);
if (sum%2) printf ("Stan wins\n");
else printf ("Ollie wins\n");
}
return 0;
}