1.题目描述:
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:
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;
}