![](https://img2020.cnblogs.com/blog/1892543/202011/1892543-20201130170157393-1057407869.png)
- 题意: 有一个分两层的圆盘,每层从12点方向均分插入(n)和(m)个隔板,当内层和外层的隔板相连时是不能通过的,有(q)个询问,每次给你内层或外层的两个点,判断是否能从一个点走到另外一个点.
- 题解: 因为是均分,所以内层和外层隔板相连的个数为(gcd(n,m)),不懂的可以从角度方向来考虑,将(360)度分成(n)和(m)个(360/n)度和(360/m)度,不难看出是gcd,接下来的就好搞了,从整体上看,我们将这个大圆分成了(gcd(n,m))块,所以我们只要判断给出的两个点是不是在同一个块中即可.
- 代码:
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define int long long
int n,m,q;
int sx,sy,ex,ey;
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m>>q;
ll gcd=__gcd(n,m);
ll cnt1=n/gcd;
ll cnt2=m/gcd;
while(q--){
cin>>sx>>sy>>ex>>ey;
if(sx==1 && ex==1){
if((sy-1)/cnt1+1==(ey-1)/cnt1+1) cout<<"YES
"; //(x-1)/y+1 表示上取整
else cout<<"NO
";
}
else if(sx==1 && ex==2){
if((sy-1)/cnt1+1==(ey-1)/cnt2+1) cout<<"YES
";
else cout<<"NO
";
}
else if(sx==2 && ex==1){
if((sy-1)/cnt2+1==(ey-1)/cnt1+1) cout<<"YES
";
else cout<<"NO
";
}
else{
if((sy-1)/cnt2+1==(ey-1)/cnt2+1) cout<<"YES
";
else cout<<"NO
";
}
}
return 0;
}