P1170 兔八哥与猎人 题解
好像是远古模拟赛的题,当时蒟蒻卡了很久,发现原题补一发题解。
难度:普及-
考点:阅读题意,抽象,gcd
给出一个
考虑看见的定义,因为光沿直线传播,只要在两个人的连线上不存在障碍物即结点就可以互相看到。
如图,当
| B | 5 | |
|---|---|---|
| 4 | ||
| 3 | ||
| A | 2 | |
| 3 | 2 | 1 |
显然
因此只要
做差
利用最大公约数判断两者是否互质(没有公共因子)
#include<bits/stdc++.h>
using namespace std;
int n,ax,ay,bx,by;
int gcd(int x,int y){
if(y==0) return x;
return gcd(y,x%y);
}
int main()
{
cin>>n;
while(n--){
cin>>ax>>ay>>bx>>by;
if(gcd(abs(ax-bx),abs(ay-by))==1) cout<<"no"<<endl;
else cout<<"yes"<<endl;
}
return 0;
}