Treasure Hunt

本文介绍了一个关于寻宝挑战的算法问题,通过判断角色能否利用特定的传送药水到达宝藏位置。文章提供了一段C++代码实现,展示了如何通过判断坐标差值与药水效果值之间的关系来解决这个问题。
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;
}

 

 

 

转载于:https://www.cnblogs.com/huangdalaofighting/p/7025917.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值