Codeforces 817A Treasure Hunt

5 篇文章 0 订阅
5 篇文章 0 订阅

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).

Example
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:

  1. — the first type of move
  2. — the third type of move 
题目大意:
给你一个起点一个终点,从起点开始经过某些变换后,能否走到终点

Hint:
首先判断从起点到终点的x方向上的距离xx能否被x整除或者从起点到终点y方向上的距离yy能否被y整除,只要其中有一个不能,就是NO
其次,判断(xx/x)%2是否等于(yy/y)%2,这个问题大家画一下图就明白啦

AC代码
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;

int main() {
	int x1, y1, x2, y2, xx, yy;
	cin >> x1 >> y1 >> x2 >> y2 >> xx >> yy;
	if (abs(x1 - x2) % xx != 0 || abs(y1 - y2) % yy != 0) {
		cout << "NO" << endl;
	}
	else {
		if ((abs(x1 - x2) / xx) % 2 == abs(y1 - y2) / yy % 2) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值