CF - 817A. Treasure Hunt - 思维

1.题目描述:

A. 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:

  1.  — the first type of move
  2.  — the third type of move

2.题意概述:

(a,b)有四种操作分别为


给你初始的(a,b)和终止状态的(a1,b1),问你是否可能通过有限次操作使得它的变换成立?

3.解题思路:

容易发现,(a,b)变换成了(a+k1x, b+k2y),那么k1和k2的奇偶性一定是相同的,还有一种特殊情况就是k1,k2不是整数,这个可以特判一下就行。

4.AC代码:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100010
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	long _begin_time = clock();
#endif
	int x1, y1, x2, y2, x, y;
	while (~scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x, &y))
	{
		double cnt1 = abs(1.0 * x2 - x1) / x;
		double cnt2 = abs(1.0 * y2 - y1) / y;
	//	printf("%.4f %.4f\n", cnt1, cnt2);
		if ((cnt1 - floor(cnt1)) > eps || (cnt2 - floor(cnt2) > eps))
		{
			puts("NO");
			continue;
		}
		puts(((int)cnt1 & 1) == ((int)cnt2 & 1) ? "YES" : "NO");
	}
#ifndef ONLINE_JUDGE
	long _end_time = clock();
	printf("time = %ld ms.", _end_time - _begin_time);
#endif
	return 0;
} 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值