【2020年杭电暑假第九场】6869 Slime and Stones

【2020年杭电暑假第九场】6869 Slime and Stones 扩展威佐夫博弈


传送门: http://acm.hdu.edu.cn/showproblem.php?pid=6869

题意

有 两 堆 石 子 , 有 两 种 拿 取 的 方 式 , 一 : 在 一 堆 中 拿 任 意 多 个 石 子 , 二 : 在 两 堆 中 拿 相 差 不 能 超 过 k 的 石 子 个 数 , 问 最 后 谁 赢 。 有两堆石子,有两种拿取的方式,一:在一堆中拿任意多个石子,二:在两堆中拿相差不能超过k的石子个数,问最后谁赢。 k

思路

这 题 就 是 威 佐 夫 博 弈 的 扩 展 , 本 来 的 威 佐 夫 博 弈 是 k = 0 , 但 是 这 里 , k > = 0 , 那 该 怎 么 办 呢 ? 这题就是威佐夫博弈的扩展,本来的威佐夫博弈是k=0,但是这里,k>=0,那该怎么办呢? k=0k>=0

还 是 从 最 开 始 的 思 路 推 起 , 对 于 两 堆 的 石 子 分 别 为 x 和 y 时 ( x < y ) : 还是从最开始的思路推起,对于两堆的石子分别为x和y时(x<y): xyx<y

d = 0 时 , 第 k 个 奇 异 局 势 为 ( [ 1 + 5 2 k ] , [ 3 + 5 2 k ] ) , k = y − x d=0时,第k个奇异局势为([\frac{1+\sqrt 5}{2}k],[\frac{3+\sqrt 5}{2}k]),k=y-x d=0k([21+5 k],[23+5 k])k=yx

这 是 要 求 ∣ d x − d y ∣ < 1 \red{这是要求|dx-dy|<1} dxdy<1

这 是 根 据 B e t t y 定 理 推 出 来 的 , 1 x + 1 x + 1    =    1 , 这 里 的 一 个 正 解 为 1 + 5 2 , 只 要 判 断 1 + 5 2 ∗ ( y − x ) = = x & & 3 + 5 2 ∗ ( y − x ) = = y 就 代 表 先 手 必 输 , 一 般 的 模 板 只 要 求 其 中 的 一 个 条 件 即 可 , 因 为 d = 0 不 需 要 考 虑 精 度 问 题 , 但 是 当 d ! = 0 时 , 考 虑 精 度 问 题 , 还 是 两 个 条 件 都 判 断 一 下 。 这是根据Betty定理推出来的,\blue{\frac{1}{x}+\frac{1}{x+1}\;=\;1},这里的一个正解为\blue{\frac{1+\sqrt 5}{2}},只要判断\frac{1+\sqrt 5}{2}*(y-x)==x \&\& \frac{3+\sqrt 5}{2}*(y-x)==y就代表先手必输,一般的模板只要求其中的一个条件即可,因为d=0不需要考虑精度问题,但是当d!=0时,考虑精度问题,还是两个条件都判断一下。 Bettyx1+x+11=121+5 21+5 (yx)==x&&23+5 (yx)==yd=0d!=0

d > 0 时 , 第 k 个 奇 异 局 势 为 ( [ 2 − d + d 2 + 4 2 k ] , [ 2 + d + d 2 + 4 2 k ] ) , k = y − x d , x 和 y 也 就 相 差 个 d k , 就 是 上 面 为 什 么 可 以 取 两 个 条 件 。 d>0时,第k个奇异局势为([\frac{2-d+\sqrt{d^2+4}}{2}k],[\frac{2+d+\sqrt {d^2+4}}{2}k]),k=\frac{y-x}{d},x和y也就相差个dk,就是上面为什么可以取两个条件。 d>0k([22d+d2+4 k],[22+d+d2+4 k])k=dyx,xydk

这 里 要 求 ∣ d x − d y ∣ < d \red{这里要求|dx-dy|<d} dxdy<d

根 据 B e t t y 定 理 , 这 里 的 解 为 1 x + 1 x + d = 1 , 所 以 我 们 只 需 要 判 断 以 下 两 个 条 件 即 可 。 根据Betty定理,这里的解为\frac{1}{x}+\frac{1}{x+d}=1,所以我们只需要判断以下两个条件即可。 Bettyx1+x+d1=1

[ 2 − d + d 2 + 4 2 k ] = = x      & &      [ 2 + d + d 2 + 4 2 k ] = = y ( 先 手 必 输 ) [\frac{2-d+\sqrt{d^2+4}}{2}k]==x\;\;\&\&\;\;[\frac{2+d+\sqrt {d^2+4}}{2}k]==y(先手必输) [22d+d2+4 k]==x&&[22+d+d2+4 k]==y()

注 意 d 输 入 之 后 要 + + , 这 里 的 k 是 y − x d , 向 下 取 整 , 所 以 由 于 精 度 问 题 , 需 要 判 断 两 个 条 件 更 精 准 。 \red{注意d输入之后要++},这里的k是\frac{y-x}{d},向下取整,所以由于精度问题,需要判断两个条件更精准。 d++kdyx

参考:大佬

Code(109MS)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pdd;

#define INF 0x7f7f7f
#define mem(a, b) memset(a , b , sizeof(a))
#define FOR(i, x, n) for(int i = x;i <= n; i++)

// const ll mod = 998244353;
// const ll P = 1e9 + 7;
// const int maxn = 1e5 + 10;
// const double eps = 1e-6;

void weizuofu()
{
    
    
    ll a, b;
    double k;
    scanf("%lld%lld%lf",&a,&b,&k);
    k += 1.0;
    if(a > b)
        swap(a , b);
    ll temp = (b - a) / k;
    ll ans1 = temp * ((sqrt(4.0 + k * k) - k + 2.0) / 2.0);
    ll ans2 = temp * ((sqrt(4.0 + k * k) + k + 2.0) / 2.0);
    if(ans1 == a && ans2 == b)
        printf("0\n");
    else
        printf("1\n");
}


void solve() {
    
    
    int T;
    scanf("%d",&T);
    while(T--) {
    
    
        weizuofu();
    }
}

signed main() {
    
    
    ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr);
#ifdef FZT_ACM_LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    signed test_index_for_debug = 1;
    char acm_local_for_debug = 0;
    do {
    
    
        if (acm_local_for_debug == '$') exit(0);
        if (test_index_for_debug > 20)
            throw runtime_error("Check the stdin!!!");
        auto start_clock_for_debug = clock();
        solve();
        auto end_clock_for_debug = clock();
        cout << "Test " << test_index_for_debug << " successful" << endl;
        cerr << "Test " << test_index_for_debug++ << " Run Time: "
             << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
        cout << "--------------------------------------------------" << endl;
    } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
    solve();
#endif
    return 0;
}

由于我一直没有注意到把&&写成||,导致一直都在WA,但是一想到我是个傻逼,所有事情都迎刃而解了,哈哈哈!

猜你喜欢

转载自blog.csdn.net/fztsilly/article/details/108084985