uva 1567

题目链接:uva 1567 - A simple stone game

题目大意:给定K和N。表示一堆石子有N个。先手第一次能够取1~N-1个石子,取到最后一个石子的人胜利,单词每次操作时,取的石子数不能超过对手上一次取的石子数m的K倍。

问先手能否够必胜。能够输出最小的首次操作。

解题思路:这题想了一天,又是打表找规律。又是推公式的,楞是做不出来,后来在网上找到了一篇题解,将的非常清楚,解题宝典

/*******************
 * K倍动态减法游戏
 * 參考:http://www.cnblogs.com/jianglangcaijin/archive/2012/12/19/2825539.html
*******************/


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 1e6+5;

int N, K, a[maxn], b[maxn];

int main () {
    int cas;
    scanf("%d", &cas);
    for (int i = 1; i <= cas; i++) {
        scanf("%d%d", &N, &K);
        int p = 0, q = 0;
        a[0] = b[0] = 0;
        while (a[p] < N) {
            a[p+1] = b[p] + 1;
            p++;

            while (a[q + 1] * K < a[p])
                q++;
            b[p] = b[q] + a[p];
        }

        printf("Case %d: ", i);
        if (N == a[p])
            printf("lose
");
        else {
            int ans;
            while (N) {
                if (N >= a[p]) {
                    N -= a[p];
                    ans = a[p];
                }
                p--;
            }
            printf("%d
", ans);
        }
    }
    return 0;
}
【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/llguanli/p/8525244.html