zoukankan      html  css  js  c++  java
  • 【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3404

    写挫好几次。。。。

    裸的博弈论即可。。

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    using namespace std;
    #define rep(i, n) for(int i=0; i<(n); ++i)
    #define for1(i,a,n) for(int i=(a);i<=(n);++i)
    #define for2(i,a,n) for(int i=(a);i<(n);++i)
    #define for3(i,a,n) for(int i=(a);i>=(n);--i)
    #define for4(i,a,n) for(int i=(a);i>(n);--i)
    #define CC(i,a) memset(i,a,sizeof(i))
    #define read(a) a=getint()
    #define print(a) printf("%d", a)
    #define dbg(x) cout << #x << " = " << x << endl
    #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
    inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
    inline const int max(const int &a, const int &b) { return a>b?a:b; }
    inline const int min(const int &a, const int &b) { return a<b?a:b; }
     
    const int N=1000005;
    bool f[N], vis[N];
    bool dfs(int x) {
        if(vis[x]) return f[x];
        if(x==0) return 0;
        vis[x]=1;
        int t=x, mx=0, mn=10;
        while(t) {
            int k=t%10;
            t/=10;
            if(k) mx=max(mx, k), mn=min(mn, k);
        }
        if(!dfs(x-mn)) return f[x]=1;
        if(!dfs(x-mx)) return f[x]=1;
        return f[x]=0;
    }
    int main() {
        int n=getint();
        while(n--) {
            int ans=dfs(getint());
            ans?puts("YES"):puts("NO");
        }
        return 0;
    }
    

    Description

        贝茜和约翰在玩一个数字游戏.贝茜需要你帮助她.
        游戏一共进行了G(1≤G≤100)场.第i场游戏开始于一个正整数Ni(l≤Ni≤1,000,000).游
    戏规则是这样的:双方轮流操作,将当前的数字减去一个数,这个数可以是当前 数字的最大数码,也可以是最小的非0数码.比如当前的数是3014,操作者可以减去1变成3013,也可以减去4变成3010.若干次操作之后,这个数字 会变成0.这时候不能再操作的一方为输家.    贝茜总是先开始操作.如果贝茜和约翰都足够聪明,执行最好的策略.请你计算最后的赢家.
        比如,一场游戏开始于13.贝茜将13减去3变成10.约翰只能将10减去1变成9.贝茜再将9减去9变成0.最后贝茜赢.

    Input

        第1行输入一个整数G,之后G行一行输入一个Ni.

    Output

     
        对于每一场游戏,若贝茜能赢,则输出一行“YES”,否则输幽一行“NO”

    Sample Input

    2
    9
    10

    Sample Output

    YES
    NO

    HINT

    For the first game, Bessie simply takes the number 9 and wins.
    For the second game, Bessie must take 1 (since she cannot take 0), and then
    FJ can win by taking 9.

    Source

  • 相关阅读:
    Project项目视图
    Console(控制台视图)
    Layout布局列表
    Layers层列表
    帐户下拉
    TransformGizmo(变换)切换
    Play播放控件
    变换工具
    工具栏
    Help帮助
  • 原文地址:https://www.cnblogs.com/iwtwiioi/p/3971921.html
Copyright © 2011-2022 走看看