zoukankan      html  css  js  c++  java
  • Treasure Hunt

    Treasure Hunt
    time limit per test 1 second
    memory limit per test 256 megabytes
    input standard input
    output standard output

    Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.

    Bottle with potion has two values x and y written on it. These values define four moves which can be performed using the potion:

    Map shows that the position of Captain Bill the Hummingbird is (x1, y1) and the position of the treasure is (x2, y2).

    You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).

    The potion can be used infinite amount of times.

    Input

    The first line contains four integer numbers x1, y1, x2, y2 ( - 105 ≤ x1, y1, x2, y2 ≤ 105) — positions of Captain Bill the Hummingbird and treasure respectively.

    The second line contains two integer numbers x, y (1 ≤ x, y ≤ 105) — values on the potion bottle.

    Output

    Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).

    Examples
    input
    0 0 0 6
    2 3
    output
    YES
    input
    1 1 3 6
    1 5
    output
    NO
    Note

    In the first example there exists such sequence of moves:

     — the first type of move

     — the third type of move

    题解:

    做了两次codeforces之后发现上面的题目很多没有看起来那么复杂,实际上只需要判断一下是否可以整除并且整除之后奇偶性是不是一样的就可以了。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<ctime>
    #include<vector>
    using namespace std;
    int x,x2,y,y2,a,b;
    int main()
    {
        int i,j;
        cin>>x>>y>>x2>>y2;
        cin>>a>>b;
        i=abs(x2-x);j=abs(y2-y);
        if(i%a==0&&j%b==0&&((i/a)%2==(j/b)%2))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
  • 相关阅读:
    Python中Random随机数返回值方式
    SQL跨库查询
    正则表达式基本语法
    excel VBA使用教程
    使用某些Widows API时,明明包含了该头文件,却报错“error C2065: undeclared identifier”
    电脑开机后数字键盘为关闭状态
    编译Boost 详细步骤 适用 VC6 VS2003 VS2005 VS2008 VS2010
    变量作用域,不能理解,先记下
    解决MySQL 在 Java 检索遇到timestamp空值时报异常的问题
    Annotation
  • 原文地址:https://www.cnblogs.com/huangdalaofighting/p/7025917.html
Copyright © 2011-2022 走看看