CodeForces - 817A Treasure Hunt

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

回头再看这题还是觉得很有趣…..

首先,容易看出,终点坐标必须是移动操作的倍数,不然移不到,这很好理解,如果不是的话,只能在终点附近反复横跳。

其次,以起点(0,0),终点(0,6),移动操作(2,3)的样例为例,x坐标的移动操作其实毫无意义,但是题目规定你必须做,就必须先移一发,再移回来。这就要求真正有效的操作必须要么都是奇数倍要么都是偶数倍,不然无法抵消无效操作,移不回来。

所以解题步骤就很明朗了:

1、取绝对值(伪·修正坐标系)

2、判断移动操作是否能被终点坐标整除。

3、如满足2,则判断移动操作是否与终点坐标是否是同样的倍数。

ac代码:

#include
using namespace std;
typedef long long ll;

int main() {
    int x1, y1, x2, y2, ox, oy;
    scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &ox, &oy);
    x2 = abs(x1 - x2);
    y2 = abs(y1 - y2);
    if(x2 % ox == 0 && y2 % oy == 0) {
        x2 /= ox;
        y2 /= oy;
        if(x2 % 2 == y2 % 2) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

你可能感兴趣的:(ACM,思维)