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. HM必修1

    高中数学必修一 笔记与拓展 1. 集合与函数概念 集合概念 集合是一个基本的数学概念. 集合是由集合的元素构成的. 当且仅当两个集合中包含着完全相同的元素且都不包含其它元素时两个集合相等. 集合是确定 ...

  2. Android 下载文件及写入SD卡

    Android 下载文件及写入SD卡,实例代码 <?xml version="1.0" encoding="utf-8"?> <LinearL ...

  3. Android app主线程UI更新间歇性崩溃的问题

    对App进行开发测试时,偶尔出现app崩溃的问题.日志如下: 10-25 18:44:52.935 15290-15290/com.zzq.cnblogs E/AndroidRuntime﹕ FATA ...

  4. android.mk文件里的通配符

    比方你有如下目录,要编译Classes目录和Code目录下所有cpp src |-android.mk |-Classes |-A.cpp |-B.cpp |-....cpp |-Code |-E.c ...

  5. apache AllowEncodedSlashes 允许URL中对路径分隔符进行编码

    2013年11月29日 10:35:32 情景: 你想通过在当前的URL中记录来源页面的URL,以便处理完请求后再跳转回来源页: http://www.example1.com/refer/http: ...

  6. 关于php中数据访问的几点补充

    前几篇文章说了,parent.self.static关键字的使用,parent可以访问父类的静态方法和静态变量,self和static可以访问本类的静态成员等等,但实际上他们还有其他作用,来看一下: ...

  7. Ubuntu的一些常用快捷键

    Ubuntu操作基本快捷键 * 打开主菜单 = Alt + F1 * 运行 = Alt + F2 * 显示桌面 = Ctrl + Alt + d * 最小化当前窗口 = Alt + F9 * 最大化当 ...

  8. Java删除文件夹和文件

    转载自:http://blog.163.com/wu_huiqiang@126/blog/static/3718162320091022103144516/ 以前在javaeye看到过关于Java操作 ...

  9. [Android Memory] Android Zipalign zip对齐优化app程序

    转载地址:http://www.cnblogs.com/xirihanlin/archive/2010/04/12/1710164.html 参考文章:http://www.cnblogs.com/l ...

  10. php 面向对象要点汇总

    //类和对象//对象:一切东西都可以看做对象,对象是类的实例化.//类:类是对象的抽象,用来描述众多对象共有的特征. //定义类 class//成员变量 和 成员方法//访问修饰符 public共有的 ...