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. [Effective JavaScript 笔记]第47条:绝不要在Object.prototype中增加可枚举的属性

    之前的几条都不断地重复着for...in循环,它便利好用,但又容易被原型污染.for...in循环最常见的用法是枚举字典中的元素.这里就是从侧面提出不要在共享的Object.prototype中增加可 ...

  2. 开机提示grub可咋办啊

    导读 GRUB是多启动规范的实现,它允许用户可以在计算机内同时拥有多个操作系统,并在计算机启动时选择希望运行的操作系统.GRUB可用于选择操作系统分区上的不同内核,也可用于向这些内核传递启动参数. 1 ...

  3. 不同版本的name可以重复

    - validates :name, presence: true, uniqueness: { conditions: -> { where(:state.ne => 2) } }, l ...

  4. Cocos2d坐标系转换

    Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系(高中数学里面那种). 笛卡尔坐标系 笛卡尔坐标系中定义右手系原点在左下角,x向右,y向上,z向外,OpenGL坐标系为笛卡尔右 ...

  5. ASP注入靶机

     ASP:   <%  Dim Db,MyDbPath dim conn '可修改设置一:========================定义数据库类别,1为SQL数据库,0为Access数据库 ...

  6. Aptana插件安装到eclipse和myeclipse的详细过程

    刚开始学习Jquery,为了搭建好的环境是很重要的,所以我尝试了很多方式,下面之一. 一.要下载好Aptana 插件 官网: http://update1.aptana.org/studio/3.2/ ...

  7. [官方教程] [ES4封装教程]2.使用 Easy Sysprep v4 封装 Windows XP

    (一)备份当前操作系统封装的第一步,其实是备份当前安装好的操作系统.避免我们在之后的步骤中出现问题,以至于还要重新安装操作系统,浪费时间精力.系统备份想必大家都会.对于WinXP而言,建议使用Ghos ...

  8. Linux 磁盘的组成

    基本结构 磁道,扇区,柱面和磁头数 硬盘最基本的组成部分是由坚硬金属材料制成的涂以磁性介质的盘片,不同容量硬盘的盘片数不等.每个盘片有两面,都可记录信息. 每个磁道被分成许多扇形的区域,每个区域叫一个 ...

  9. 新浪云php与java连接MySQL数据库

    PHP新浪云连接MySQL <?php $con=mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYS ...

  10. python代码中使用settings

    在具体的Django应用中,通过引入 django.conf.settings 使用配置,例: from django.conf import settings settings.configure( ...