QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓

#6725. 拾取

统计

网格城(Grid City)是一个位于无限二维平面上的城市,对于所有的 $k \in \mathbb{Z}$($\mathbb{Z}$ 为整数集),直线 $x = k$ 和 $y = k$ 构成了城市的街道。人们只能沿着道路从一个位置移动到另一个位置。这就是该城市被称为“网格城”的原因!

两位朋友,BaoBao 和 DreamGrid,快乐地生活在这个城市里。今天,BaoBao 正从他位于 $(x_A, y_A)$ ($x_A, y_A \in \mathbb{Z}$) 的家出发,前往位于 $(x_C, y_C)$ ($x_C, y_C \in \mathbb{Z}$) 的购物中心。然而,步行去那里太远了,所以他决定打电话给家位于 $(x_B, y_B)$ ($x_B, y_B \in \mathbb{Z}$) 的 DreamGrid 寻求帮助。

BaoBao 和 DreamGrid 同时从各自的家中出发。与步行速度为每分钟 $a$ 个单位的 BaoBao 不同,DreamGrid 开车,速度为每分钟 $b$ 个单位。当 DreamGrid 和 BaoBao 在同一点相遇时,DreamGrid 可以接上 BaoBao,然后他们可以一起以每分钟 $b$ 个单位的速度移动。掉头或接上 BaoBao 不需要时间。

BaoBao 从家到购物中心所需的最短时间是多少?注意,如果 BaoBao 自己前往目的地更快,则不需要 DreamGrid 接他。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试数据的组数。对于每组测试数据:

第一行包含两个整数 $a$ 和 $b$ ($1 \le a < b \le 10^9$),分别表示 BaoBao 的步行速度和 DreamGrid 的驾驶速度。

第二行包含六个整数 $x_A, y_A, x_B, y_B, x_C$ 和 $y_C$ ($-10^9 \le x_A, y_A, x_B, y_B, x_C, y_C \le 10^9$),分别表示 BaoBao 的家、DreamGrid 的家以及购物中心的位置。保证这三个点互不相同。

输出格式

对于每组测试数据,输出一行包含一个数字,表示 BaoBao 到达购物中心的最短时间。如果你的答案的绝对误差或相对误差不超过 $10^{-6}$,则视为正确。

样例

样例输入 1

3
1 2
0 2 1 0 2 2
1 3
1 1 0 1 3 1
1 2
0 0 100 100 1 1

样例输出 1

1.500000000000000
1.000000000000000
2.000000000000000

说明

样例测试数据如右图所示。 对于第一个样例,BaoBao 和 DreamGrid 将在 $D(1, 2)$ 相遇,然后 DreamGrid 开车送 BaoBao 去购物中心。 对于第二个样例,BaoBao 和 DreamGrid 将在 $D(1.5, 1)$ 相遇,然后 DreamGrid 开车送 BaoBao 去购物中心。

Figure 1. 样例测试数据示意图

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.