CodeForces - 817A Treasure Hunt

本文介绍了一项有趣的寻宝挑战,通过分析给定的坐标和传送药水的能力,判断是否能够成功找到宝藏。主要讨论了如何利用数学方法确定目标位置是否可达。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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<bits/stdc++.h>
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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值