BZOJ 4147: [AMPPZ2014]Euclidean Nim(复杂的分类讨论与简单的博弈论)

版权声明:本文为博主原创文章,未经博主允许必须转载。 https://blog.csdn.net/qq_35950004/article/details/88639436

大佬 %%%
对于三者的关系疯狂分类讨论即可,还需要一点点灵性的结论。
AC Code:

#include<bits/stdc++.h>
using namespace std;
int n,p,q;
int main(){
	int T;
	for(scanf("%d",&T);T--;){
		scanf("%d%d%d",&p,&q,&n);
		int gcd = __gcd(p,q);
		if(n%gcd){puts("R");continue;}
		p/=gcd,q/=gcd,n/=gcd;
		if(p==q) puts("E");
		else if(p>q && n<p) puts("P");
		else if(p>q && n>=p && (n%p)<q && (n%p)%(p-q)==0) puts("E");
		else if(p<q && n>=p) puts("E");
		else if(p<q && n<p && n+p<q) puts("E");
		else if(p<q && n<p && n+p>=q && (((n+p)%q)>=p || ((n+p)%q)%(q-p)!=0)) puts("E");
		else puts("P");
	}
}

猜你喜欢

转载自blog.csdn.net/qq_35950004/article/details/88639436