[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();
    }
}
原文地址:https://www.cnblogs.com/mollnn/p/14090225.html