【CodeForces - 1200C】Round Corridor (数论gcd)
Round Corridor
Descriptions
Amugae位于一个非常大的圆形走廊中。走廊由两个区域组成。内部区域等于nñ扇区,外部区域等于m米部门。在相同区域(内部或外部)的每对扇区之间存在壁,但在内部区域和外部区域之间没有壁。墙壁始终存在于12点钟位置。
内部区域的扇区被表示为(1,1),(1,2),...,(1,Ñ)(1,1),(1,2),…,(1,ñ)顺时针方向。外部区域的扇区被表示为(2,1),(2,2),...,(2,米)(2,1),(2,2),…,(2,米)以相同的方式。有关清楚的理解,请参阅上面的示例图像。
Amugae想知道他是否可以从一个部门转移到另一个部门。他有q个问题。
对于每个问题,检查他是否可以在两个给定的扇区之间移动。
Input
第一行包含三个整数n,m和q(1≤n,m≤1018 ,1≤n,m≤1018,1≤q≤104,1≤q≤104) - 内部区域的扇区数,扇区数在外部区域和问题的数量。 每个下一个q行包含四个整数sx,sy,ex,ey。 Amague想要知道是否有可能从扇区(sx,sy)(sx,sy)转移到扇区(ex,ey)(例如,ey)。
Output
对于每个问题,如果Amugae可以从(sx,sy)(sx,sy)移动到(ex,ey)(ex,ey),则打印“YES”,否则打印“NO”。 您可以在任何情况下(上部或下部)打印每个字母
Example
Input4 6 3 1 1 2 3 2 6 1 2 2 6 2 4
OutputYES NO YES
Note
示例显示在声明中的图片上。
题目链接
https://vjudge.net/problem/CodeForces-1200C
AC代码
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>1
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 100005
using namespace std;
ll n,m,q;
ll sx,sy,ex,ey;
int main()
{
cin>>n>>m>>q;
ll g=__gcd(n,m);
n/=g;
m/=g;
while(q--)
{
cin>>sx>>sy>>ex>>ey;
sy--,ey--;
ll t1,t2;
if(sx==1)
t1=n;
if(sx==2)
t1=m;
if(ex==1)
t2=n;
if(ex==2)
t2=m;
if((sy/t1)==(ey/t2))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}