当前位置: 移动技术网 > IT编程>脚本编程>Shell > Codeforces 1451D. Circle Game(博弈)

Codeforces 1451D. Circle Game(博弈)

2020年11月25日  | 移动技术网IT编程  | 我要评论
DescriptionExampleinput52 15 210 325 415441 33outputUtkarshAshishUtkarshUtkarshAshishSolution典型对称博弈先计算出若右/上交替着走能走的最远步数k若k为奇数:先手先随便走一步,之后的每一步都与上一步后手对称,即可使得先手必胜若k为偶数:无论先手怎么走,后手都与其对称的走,即可使得后手必胜Codeint res;ll d,k;void dfs(ll x,ll y) {

Description
在这里插入图片描述
Example
input
5
2 1
5 2
10 3
25 4
15441 33

output
Utkarsh
Ashish
Utkarsh
Utkarsh
Ashish

Solution
典型对称博弈
先计算出若右/上交替着走能走的最远步数k
若k为奇数:先手先随便走一步,之后的每一步都与上一步后手对称,即可使得先手必胜
若k为偶数:无论先手怎么走,后手都与其对称的走,即可使得后手必胜

Code

int res;
ll d,k;
void dfs(ll x,ll y) {
	if(x > y) swap(x,y);
	ll tmp = x + k;if(tmp * tmp + y * y > d * d) return ;
	res++;dfs(tmp,y);
}
int main(int argc, char const *argv[])
{
	int T;scanf("%d",&T);
	while(T--) {
		scanf("%lld %lld",&d,&k);
		res = 0;
		dfs(0,0);
		if(res%2) printf("Ashish\n"); else printf("Utkarsh\n");
	}
	return 0;
}

本文地址:https://blog.csdn.net/qq_43521140/article/details/110144625

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网