QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#3452. 雷达

Estadísticas

在海上漂流了 80 天后,你的船耗尽了燃料。今天,你的雷达设备终于恢复了工作,并且接收到了信号!

遗憾的是,这些信号来自古怪的灯塔管理员 Hasse 所拥有的“雷达”站。Hasse 的雷达站(它的工作方式与其他雷达站不太一样)会发射三种不同波长的连续信号。因此,你唯一能测量到的有趣信息就是信号到达你这里时的相位。例如,如果你调谐的信号波长为 100 米,而你距离雷达站 1456 米,你的设备只能告诉你,你距离灯塔的距离可能是 56 米、156 米、256 米,以此类推。

于是你拿出最后一张纸开始计算——等等,这里有个陷阱!你在显示屏上读到:“精度:3 米”。所以,实际上你从该信号获得的信息是:你距离 Hasse 雷达站的距离位于区间并集 $[53, 59] \cup [153, 159] \cup [253, 259] \cup \dots$ 中。

该怎么办呢?既然在海上生存的关键是保持乐观,你现在感兴趣的是:给定三种信号对应的波长、测量值和精度,距离灯塔的最小可能距离是多少。

题目描述

给定三个正素数 $m_1, m_2, m_3$(波长)、三个非负整数 $x_1, x_2, x_3$(测量值)以及三个非负整数 $y_1, y_2, y_3$(精度),求最小的非负整数 $z$(最小可能距离),使得对于每个 $i = 1, 2, 3$,都有 $z$ 在 $x_i$ 模 $m_i$ 的距离 $y_i$ 范围内。如果存在某个整数 $t$ 满足 $x' \equiv x + t \pmod{m}$ 且 $|t| \le y$,则称整数 $x'$ 在 $x$ 模 $m$ 的距离 $y$ 范围内。

输入格式

输入共有三行。第一行包含 $m_1, m_2, m_3$,第二行包含 $x_1, x_2, x_3$,第三行包含 $y_1, y_2, y_3$。你可以假设对于每个 $i$,都有 $0 < m_i \le 10^6$,$0 \le x_i < m_i$,且 $0 \le y_i \le 300$。$m_1, m_2, m_3$ 均为互不相同的素数。

输出格式

输出一行,包含答案 $z$。注意,答案可能无法用 32 位整数存储。

样例

样例输入 1

11 13 17
5 2 4
0 0 0

样例输出 1

2095

样例输入 2

941 947 977
142 510 700
100 100 100

样例输出 2

60266

Figure 1. Hasse's radar station

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.