CodeForces - 817A - Treasure Hunt【 思维 】题解

1.题目

Captain Bill the Hummibird 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 (x 1, y 1) and the position of the treasure is (x 2, y 2).
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 x 1, y 1, x 2, y 2 ( - 105 ≤ x 1, y 1, x 2, y 2 ≤ 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
Sponsor

2.题意

一个人去找宝藏,已知他现在的坐标和宝藏的坐标,他有一种药水会让他瞬间移动,这个药水的值是(a,b),他喝了之后会向四周(+a,+b),(-a,-b),(-a,+b),(+a,-b)四个方向移动,药水能喝无数次,问他能否到终点。

3.思路

终点坐标和起点坐标的差值必须是移动步数的倍数,否则移不到。x方向移动的是a的奇数倍,而y方向上移动的是b的偶数倍时,这个点并不能走到。也就是说x,y方向上的移动次数必须同奇偶。满足以上两个条件即可移到。

4代码

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	int x1, x2, y1, y2;
	int x, y;
	cin >> x1 >> y1 >> x2 >> y2 >> x >> y;
	if (abs(x2 - x1) %x == 0&& abs(y2 - y1) %y ==0)
	{
		int t1 = abs(x2 - x1) / x;
		int t2 = abs(y2 - y1) / y;
		if (t1 % 2 == t2 % 2)         //同奇偶
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45629285/article/details/106555665
今日推荐