Ural 1286. Starship Travel

Source: Internet
Author: User
Tags gcd

1286. Starship TravelTime limit:1.0 Second
Memory limit:64 MBIt is well known, a starship equipped with class B Hyperengine are 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 and the damaged Hyperengine the vehicle can move from a point with coordinates ( I, JFrom the following list: ( I+ Q, J+ P), ( IQ, J+ P), ( I+ Q, JP), ( IQ, JP), ( I+ P, J+ Q), ( IP, J+ Q), ( I+ P, JQ), ( IP, JQ) (all the coordinates here is integers and is given in the standard Intergalaxy system). Help the captain of your ship to find out if the ship was able to reach the destination planet on its own or a repair ship Must be called. Inputthe first line contains, integers Pand Q(The remaining discrete power rates of the damaged hyperengine) separated with a space. The second line contains the coordinates of the where the-the-spaceship is now. The third line contains the coordinates of the destination planet. The numbers in the second and third lines is also separated with spaces. All the numbers is integers and does not exceed 2 109 in absolute value. Outputif the commander can move the damaged starship to the destination planet, write ' YES '. Write ' NO ' If a repair ship must is called. Samples
input Output
4 60 010 10
YES
4 60 09 9
NO
problem Author:Alexander Klepinin
problem Source:USU Personal Contest 2004 Tags:Number theory()difficulty:693 Test Instructions: The main point is to give the p,q, as well as the origin (Sx,sy), the end point (ex, EY), each time from (x, y) (x+-p y+-q) or (x+-q, y +-P), ask can from the starting point to the end point. Analysis: First, because no matter the number of steps, so the change in X, y must be gcd (p, Q) of the integer times the G = gcd (p, q) so if ABS (EX-SX), ABS (EY-SY) can not be divisible by G, it is not. Make x = ABS (EX-SX), y = ABS (Ey-sy) divide x, Y, p, q all by g means that now x, Y, p, q all represent the least number of times then we assume that each step becomes g, because this is obviously possible ... If x, Y and the same parity, then obviously can reach, even if the x direction, the number of times in the Y direction is not the same, but can be +g again-G do two times do not work to keep the parity, and remain in place if p,q different odd and even, then it is also possible, because p,q a odd and even, Obviously can form any desired number (because no matter how many times) actually online blog better my solving a bit of stream of consciousness ... Note that the case of p = = q = 0 is handled
1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <cmath>5#include <deque>6#include <vector>7#include <queue>8#include <iostream>9#include <algorithm>Ten#include <map> One#include <Set> A#include <ctime> - using namespacestd; -typedefLong LongLL; thetypedefDoubleDB; - #defineFor (I, S, T) for (int i = (s); I <= (t); i++) - #defineFord (I, S, T) for (int i = (s); I >= (t); i--) - #defineRep (i, T) for (int i = (0); i < (t); i++) + #defineREPN (i, T) for (int i = (t)-1); I >= (0); i--) - #defineRep (i, X, T) for (int i = (x); i < (t); i++) + #defineMIT (2147483647) A #defineINF (1000000001) at #defineMLL (1000000000000000001LL) - #defineSZ (x) ((int) (x). Size ()) - #defineCLR (x, y) memset (x, y, sizeof (x)) - #definePUF Push_front - #definePub push_back - #definePOF Pop_front in #definePOB pop_back - #defineFT first to #defineSD Second + #defineMk Make_pair -InlinevoidSetio (stringName) { the     stringInput = name+". in", *Output = name+". out"; $Freopen (Input.c_str (),"R", stdin),Panax NotoginsengFreopen (Output.c_str (),"W", stdout); - } the  +InlineintGetint () { A     intRet =0; the     CharCh =' '; +     BOOLFlag =0; -      while(! (Ch >='0'&& Ch <='9')) { $         if(Ch = ='-') Flag ^=1; $Ch =GetChar (); -     } -      while(Ch >='0'&& Ch <='9') { theRet = ret*Ten+ch-'0'; -Ch =GetChar ();Wuyi     } the     returnFlag? -Ret:ret; - } Wu  - LL p, Q, A, B, C, D; About  $InlinevoidInput () { -Cin>>p>>q>>a>>b>>c>>D; - } -  AInlineintGCD (intAintb) { +     if(b)returnGCD (b, a%b); the     Else returnA; - } $  theInlinevoidSolve () { theLL x = ABS (a-c), y = ABS (b-d), G =GCD (P, q); the     if(!g | | x%g | | y%g) { thePuts"NO"); -         return; in     } theX/= g, y/= g, p/= G, Q/=G; theX &=1, y &=1, P &=1, Q &=1; About     if(! (x^y) | | (P^Q)) Puts"YES"); the     ElsePuts"NO"); the } the  + intMain () { - #ifndef Online_judge theSetio ("D");Bayi     #endif  the Input (); the Solve (); -     return 0; -}
View Code

Ural 1286. Starship Travel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.