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.
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.
Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).
0 0 0 6
2 3
YES
1 1 3 6
1 5
NO
In the first example there exists such sequence of moves:
— the first type of move
— the third type of move
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<sstream> #include<algorithm> #include<queue> #include<deque> #include<iomanip> #include<vector> #include<cmath> #include<map> #include<stack> #include<set> #include<fstream> #include<memory> #include<list> #include<string> using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MAXN 1000009 #define N 21 #define MOD 1000000 #define INF 1000000009 const double eps = 1e-8; const double PI = acos(-1.0); inline int sgn(double t) { if (abs(t - floor(t)) < eps) return 0; else return 1; } int main() { double x1, y1, x2, y2, a, b; cin >> x1 >> y1 >> x2 >> y2; double x = abs(x2 - x1), y = abs(y2 - y1); cin >> a >> b; if (sgn((double)(x/2/a + y/2/b)) == 0 && sgn((double)(y/2/b - x/2/a)) == 0) printf("YES\n"); else printf("NO\n"); }
本文介绍了一个基于坐标移动的算法挑战,通过分析船长比尔蜂鸟能否使用特定药水达到宝藏位置的问题,探讨了算法解决方案。药水允许进行四种类型的移动,任务是判断是否有可能到达目标。




651

被折叠的 条评论
为什么被折叠?



