cf1451D. Circle Game (circle game, mathematics, game summary)

Subject link: https://codeforces.ml/contest/1451/problem/D

The meaning of the title: A and U can play any game, the first point is (0,0). Now give two integers 1<=d<=1e5,1<=k<=d. A goes first, and k must be added to the horizontal or vertical axis each time. And (x,y) must satisfy x*x+y*y<=d*d. If one party cannot go, it proves to be lost.

Problem solution: game problem, very fair game problem. At first I thought I would use the sg function or something, but I don't know how to use emmm. Almost ignored that cf focuses on thinking.

Those who can play the meter can directly play the meter, and then analyze the law. (x+y)%2==1 is A, (x+y)%2==0 is U. Now play the table with k=1.

d=10:

10
  1|||U A U A U A U A U 
  2|||A U A U A U A U A 
  3|||U A U A U A U A U 
  4|||A U A U A U A U A 
  5|||U A U A U A U A   
  6|||A U A U A U A U   
  7|||U A U A U A U 
  8|||A U A U A U   
  9|||U A U A       
 10|||

Analyze the boundary, from top to bottom U,A,U,A,U,U,U,A,U,A,U. There are more U, so U must win. (Just kidding haha).

Originally, I wanted to write the code directly when I hit here. For example, here p=7. That is, when there is no successor state at (7,7), then U wins. But the idea is not clear, and the code to realize this function has not been typed out (I gave up without adjusting it after I typed it. The decision is still thinking, otherwise it is useless, I still don’t understand, and there is a high probability of WA. Anyway, there is still a lot of time. Guess again in the last few minutes. So I thought about it for another half an hour (caiji was afraid to explain it), and finally waited for the moment of clarity).

. . . . . . Derive A's must-win and must-defe state

The final idea: (x, y), x==y must be U, if you take the largest x, (x, y) has no successor state, U will win, because first A to (1, 2) ((2, 1) The same because of symmetry), then U(2,2), and then no matter how A goes, U can always reach (x,y)x==y. So U wins.

If (x, y), x == y and (x, y) has a successor state. Then A goes to (1,2) first, and then no matter how U goes, A can go directly to a point on a line of A that is next to the axis of symmetry U (ie x, x+1), so A wins. I have to say it is very clever.

###########################################################

to sum up:

1. Game problem: Think about whether a person can pull the game to a certain state (this state is good for oneself). This is the most common way of thinking about game thinking problems. I didn't look at game theory before. How can I think about sg after reading game theory? ? ? In my opinion, the CF test is generally not that difficult.

 

Code:

#include <bits/stdc++.h>

#define ll long long
#define ld double
#define pi acos(-1)
#define pb push_back
#define mst(a, i) memset(a, i, sizeof(a))
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define rep(i,a,n)  for(ll i=a;i<=n;i++)
#define per(i,n,a)  for(ll i=n;i>=a;i--)
#define dbg(x) cout << #x << "===" << x << endl
#define dbgg(l,r,x) for(ll i=l;i<=r;i++) cout<<x[i]<<" ";cout<<endl
using namespace std;

template<class T>void read(T &x){T res=0,f=1;char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){res=(res<<3)+(res<<1)+c-'0';c=getchar();}x=res*f;}
inline void print(ll x){if(x<0){putchar('-');x=-x;}if(x>9)print(x/10);putchar(x%10+'0');}
const ll maxn = 1e5 + 10;
const ll mod = 1e9+7;

ll d,k;
//ll inv(ll a){return a==1?1:(ll)(mod-mod/a)*inv(mod%a)%mod;}
//ll gcd(ll a,ll b){return (b==0)?a:gcd(b,a%b);}
//ll qpow(ll a,ll p,ll mod){ll ans=1;a=a%mod;while(p){if(p&1)ans=(ans*a)%mod;p>>=1;a=(a*a)%mod;}return ans;}
int main() {
    ll _s = 1;
    read(_s);
    //freopen("testdata.in","r",stdin);
	//freopen("testout.out","w",stdout);
    for (ll _=1;_<=_s;_++) {
        read(d),read(k);
		ll p=1;
		for(ll i=1;;i++){
			if((i*k)*(i*k)+(i*k)*(i*k)>d*d){
				p=i;break;
			}
		}
		--p;
		// dbg(p);
		bool f=true;
		ll t=p*p*k*k+k*k*(p+1)*(p+1);
		// dbg(t);
		if(t<=d*d) f=true;
		else f=false;
		puts(f?"Ashish":"Utkarsh");
    }
    return 0;
}
/*
input:::
Utkarsh
Ashish
Utkarsh
Utkarsh
Ashish

output:::

*/

 

Guess you like

Origin blog.csdn.net/I_have_a_world/article/details/109919534