码迷,mamicode.com
首页 > 其他好文 > 详细

[CF1451D] Circle Game - 博弈论

时间:2020-12-09 12:33:28      阅读:21      评论:0      收藏:0      [点我收藏+]

标签:需要   mat   for   als   space   return   单位   答案   def   

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();
    }
}

[CF1451D] Circle Game - 博弈论

标签:需要   mat   for   als   space   return   单位   答案   def   

原文地址:https://www.cnblogs.com/mollnn/p/14090225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!