1286. Starship Travel

Time limit: 1.0 second
Memory limit: 64 MB
It is well known that a starship equipped with class B hyperengine is able to travel from any planet to any other planet. But your starship got severe damage in the last travel and now its movement ability is limited. The starship’s technician determined that with the damaged hyperengine the vehicle can move from a point with coordinates (i,j) only to a point from the following list: (i+qj+p), (iqj+p), (i+qjp), (iqjp), (i+pj+q), (ipj+q), (i+pjq), (ipjq) (all the coordinates here are integers and are given in the standard intergalaxy system). Help the captain of your ship to find out if the ship is able to reach the destination planet on its own or a repair ship must be called.

Input

The first line contains two integers p and q (the two remaining discrete power rates of the damaged hyperengine) separated with a space. The second line contains the coordinates of the point where the spaceship is now. The third line contains the coordinates of the destination planet. The numbers in the second and third lines are also separated with spaces. All the numbers are integers and do not exceed 2·109 in absolute value.

Output

If the commander can move the damaged starship to the destination planet, write ‘YES’. Write ‘NO’ if a repair ship must be called.

Samples

input output
4 6
0 0
10 10
YES
4 6
0 0
9 9
NO
Problem Author: Alexander Klepinin
Problem Source: USU Personal Contest 2004
Difficulty: 693
 
题意:看题吧,主要是说给出p,q,以及起始点(sx,sy),结束点(ex, ey),每次可以从(x, y)->(x+-p y+-q)或(x+-q, y +- p),问能不能从起始点到结束点。
分析:首先,因为不管步数,所以x、y的变化量必定都是gcd(p, q)的整数倍
令g = gcd(p, q)
所以如果abs(ex-sx)、abs(ey-sy)不能被g整除,那是不行的。
令x = abs(ex-sx), y = abs(ey - sy)
让x、y、p、q都除以g
就是说现在x、y、p、q都代表最少的次数
那我们假设每次的步伐都变成g,因为这显然是可以的。。。
如果x,y同奇同偶,那么显然可以到达,即使x方向、y方向上的次数不一样,但完全可以+g再-g做两次无用功保持奇偶性不变,并且原地不动
如果p,q不同奇同偶,那么也是可以的,因为p,q一奇一偶,显然可以组成任何想要的数(因为不计次数)
其实网上的博客更好
我的题解有点意识流了。。。
 
注意处理p == q == 0 的情况
 
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint() {
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= '')) {
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '') {
Ret = Ret*+Ch-'';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} LL p, q, a, b, c, d; inline void Input() {
cin>>p>>q>>a>>b>>c>>d;
} inline int Gcd(int a, int b) {
if(b) return Gcd(b, a%b);
else return a;
} inline void Solve() {
LL x = abs(a-c), y = abs(b-d), g = Gcd(p, q);
if(!g || x%g || y %g) {
puts("NO");
return;
}
x /= g, y /= g, p /= g, q /= g;
x &= , y &= , p &= , q &= ;
if(!(x^y) || (p^q)) puts("YES");
else puts("NO");
} int main() {
#ifndef ONLINE_JUDGE
SetIO("D");
#endif
Input();
Solve();
return ;
}

ural 1286. Starship Travel的更多相关文章

  1. Ural 1004 Sightseeing Trip

    Sightseeing Trip Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...

  2. 图论 - Travel

    Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n. Among n(n− ...

  3. hduoj 1286 找新朋友

    http://acm.hdu.edu.cn/showproblem.php?pid=1286 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  4. 【BZOJ-1576】安全路径Travel Dijkstra + 并查集

    1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1044  Solved: 363[Sub ...

  5. Linux inode && Fast Directory Travel Method(undone)

    目录 . Linux inode简介 . Fast Directory Travel Method 1. Linux inode简介 0x1: 磁盘分割原理 字节 -> 扇区(sector)(每 ...

  6. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  7. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  8. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  9. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

随机推荐

  1. 背景透明的 Dialog

    一:控制Dialog 的背景方法:1.定义一个无背景主题主题 <!--去掉背景Dialog--> <style name="NobackDialog" paren ...

  2. 淘宝(阿里百川)手机客户端开发日记第二篇 android首页之顶部轮播特效制作 (二)

    1.我们来设计flash_slide.xml 布局,这个xml主要做成模块化,方便其它的activity可以动态去调用. flash_slide.xml内容如下: <?xml version=& ...

  3. magic-encoding

    (文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 今天页面跳转都出问题了,各种方法都试过了, log里说语法错误,问了pp,他说是汉字的原因...果 ...

  4. MAC的OS X10.10更新以后进入用户界面就死机

    我用的是搜狗输入法,所以把搜狗卸载就好了.(注意是卸载,不是单纯的从输入源里移除) 下载一个搜狗输入法的DMG,打开后选择卸载搜狗输入法. 转自: http://zhidao.baidu.com/qu ...

  5. 【云计算】docker的小知识,帮你更深入理解容器技术

    关于docker的15个小tip   1. 获取最近运行容器的id 这是我们经常会用到的一个操作,按照官方示例,你可以这样做(环境ubuntu): $ ID=$(docker run ubuntu e ...

  6. js指定标签的id只能添加不能删除

    <body> <form id="form1" runat="server"> <div> <input id=&qu ...

  7. 16.O(logn)求Fibonacci数列[Fibonacci]

    [题目] log(n)时间Fib(n),本质log(n)求a^n. [代码]  C++ Code  12345678910111213141516171819202122232425262728293 ...

  8. Android Volley获取json格式的数据

    为了让Android能够快速地访问网络和解析通用的数据格式Google专门推出了Volley库,用于Android系统的网络传输.volley库可以方便地获取远程服务器的图片.字符串.json对象和j ...

  9. [Android Pro] 横竖屏切换时,禁止activity重新创建,android:configChanges="keyboardHidden|orientation" 不起作用

    referece to : http://blog.csdn.net/mybook1122/article/details/24978025 这个网上搜索,很多结果都是: AndroidManifes ...

  10. Maven简介

    转载地址:http://www.cnblogs.com/itech/archive/2011/11/01/2231837.html Ant是软件构建工具,Maven的定位是软件项目管理和理解工具.Ma ...