1. 程式人生 > 實用技巧 >[CF1451D] Circle Game - 博弈論

[CF1451D] Circle Game - 博弈論

Description

座標軸上,有一個以 \((0,0)\) 為圓點,\(d\) 為半徑的圓。現在 Ashish 和 Utkarsh 玩遊戲,Ashish 是先手。在 \((0,0)\) 處有一顆棋子,兩人輪流將棋子向上或向右移動 \(k\) 個單位,棋子不能移出圓,誰無法移動誰輸。

Solution

首先,同一根對角線上的答案相同,因為後手總可以通過與先手相反的動作來使得勝負性不變。

因此我們只需要判斷 \((n,n)\) 的狀態即可。

\((n,n)\) 不是必敗點,當且僅當 \((n+1,n)\) 在圓內。

#include <bits/stdc++.h>
using namespace std;

#define int long long

void solve()
{
    int n;
    int d;

    cin >> n >> d;
    double x = 1.0 * n / d;
    x*=x;
    for (int i = 1; i <= 1e5; i++)
    {
        if (2 * (i - 1) * (i - 1) <= x && x < i * i + (i - 1) * (i - 1))
        {
            cout << "Utkarsh" << endl;
            return;
        }
        else if (i * i + (i - 1) * (i - 1) <= x && x < 2 * i * i)
        {
            cout << "Ashish" << endl;
            return;
        }
    }
}

signed main()
{
    ios::sync_with_stdio(false);

    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}