您的位置:首页 > 其它

HDU 1525 Eculid's Game(博弈)

2016-02-25 23:10 316 查看
题意:

给你两堆物品,每次可以在数量多的那一堆中那数量少的那堆数量的倍数,
先拿完一堆的赢。
博弈太机智,伤不起TAT。。。
假设两堆分别是a,b(a>b)。如果b==1|| a%b==0 则先手必胜。
当a>=2*b时,拿的时候有两种决策,一个是拿到a%b,b,或者
a%b+b,b,因为双方足够聪明,所以说,如果拿完所有的b赢的话,
就会把局面推到a%b+b,先手赢,繁殖依然,所以说这两种情况是先手
的那个人可以选择的,他只需要往赢得子局面上推就好了。
仔细想想应该就理解了。


代码:

//
//  Created by  CQU_CST_WuErli
//  Copyright (c) 2016 CQU_CST_WuErli. All rights reserved.
//
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#define CLR(x) memset(x,0,sizeof(x))
#define OFF(x) memset(x,-1,sizeof(x))
#define MEM(x,a) memset((x),(a),sizeof(x))
#define BUG cout << "I am here" << endl
#define lookln(x) cout << #x << "=" << x << endl
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define rep(flag,start,end) for(int flag=start;flag<=end;flag++)
#define Rep(flag,start,end) for(int flag=start;flag>=end;flag--)
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
#define Root 1,n,1
#define BigInteger bign
const int MAX_L=2005;// For BigInteger
const int INF_INT=0x3f3f3f3f;
const long long INF_LL=0x7fffffff;
const int MOD=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
typedef long long  ll;
using namespace std;

const int N=2e4+100;

int a,b;

int dfs(int a,int b) {
if (a>b) swap(a,b);
if (a==0 || b%a==0 || b/a>=2) return 1;
else if (!dfs(a,b-a)) return 1;
return 0;
}

int main(int argc, char const *argv[]) {
#ifdef LOCAL
freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin);
// freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout);
#endif
while(SII(a,b)==2 && (a||b)) {
int ok=dfs(a,b);
puts(ok?"Stan wins":"Ollie wins");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: