题目:http://acm.timus.ru/problem.aspx?space=1&num=1286
题目要求 p * x1 + q * y1 = abs(ex - sx) && p * x2 + q * y2 = abs(ey - sy)同时成立,设 d = gcd(p,q) ,dx = abs(ex - sx), dy = (ey - sy),如果 (dx % d || dy % d )成立,那么从开始点一定到不了终点,否则 dx /= d, dy /= d, p /= d, q /= d;分情况讨论,详见此出http://shaidaima.com/source/view/7789
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 ll gcd(ll a,ll b) 2 { 3 if(!b) return a; 4 else return gcd(b,a % b); 5 } 6 ll tfab(ll x) 7 { 8 if(x < 0) return -x; 9 else return x; 10 } 11 int main() 12 { 13 ll p,q; 14 ll sx,sy,ex,ey; 15 //freopen("data.txt","r",stdin); 16 while(cin>>p>>q>>sx>>sy>>ex>>ey) 17 { 18 ll d = gcd(p,q); 19 ll dx = tfab(sx - ex); 20 ll dy = tfab(sy - ey); 21 if(dx == 0 && dy == 0) 22 { 23 printf("YES\n");continue; 24 } 25 if(!p && !q) 26 { 27 if(dx || dy) printf("NO\n"); continue; 28 } 29 if(dx % d || dy % d) 30 { 31 printf("NO\n"); continue; 32 } 33 dx /= d, dy /= d, p /= d, q /= d; 34 if((p % 2 == 0 && q % 2) || (p % 2 && q % 2 == 0)) 35 { 36 printf("YES\n");continue; 37 } 38 if(p % 2 && q % 2) 39 { 40 if((dx % 2 == 0 && dy % 2 == 0) || (dx % 2 && dy % 2)) printf("YES\n"); 41 else printf("NO\n"); 42 continue; 43 } 44 } 45 return 0; 46 }