CF1200C
質問の意味:
Qの別の部分から行くことができる場合、N、Mの部分は、各数字が求めている内側および外側の円に分割され、12時の線が存在しなければなりません。
ソリューション:
存在する場合、スルー壁1及び図2に示すように、側面は通信しないように。そのような壁のNまたはM /共通分母に現れる明らかであろう。
コード:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
LL n,m,q;
inline LL gcd(LL a,LL b) {
return !b ? a : gcd(b,a%b);
}
int main() {
scanf("%lld%lld%lld",&n,&m,&q);
LL G = gcd(n, m);
LL nn = n / G, mm = m / G;
while (q--) {
LL x1, y1, x2, y2;
scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
y1--, y2--;
LL ans1, ans2;
if(x1 == 1) ans1 = y1 / nn;
else ans1 = y1 / mm;
if(x2 == 1) ans2 = y2 / nn;
else ans2 = y2 / mm;
if(ans1 == ans2) puts("YES");
else puts("NO");
}
//system("pause");
return 0;
}