问题 E: Horse Drinks Water

内存限制:256 MB 时间限制:2 S
题面:Markdown 评测方式:Special Judge 上传者:
提交:6 通过:3

题目描述

This problem is a variant of the General’s Horse Drinking Water problem. Given that the general’s horse is at point $\textstyle (x_G, y_G)$, the tent is at point $\textstyle (x_T, y_T)$, and the river is located along the positive half of the x-axis and the positive half of the y-axis, find the shortest distance the horse needs to travel to drink water from the river and return to the tent.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $\textstyle t$ ($\textstyle 1 \leq t \leq 10^5$). The description of the test cases follows. Each test case consists of a single line containing four integers $\textstyle x_G, y_G, x_T, y_T$ ($\textstyle 0 \leq x_G, y_G, x_T, y_T \leq 10^9$), describing the positions of the general’s horse and the tent.

输出格式

For each test case, output a decimal number representing the shortest distance the horse needs to travel to drink water from the river and return to the tent. Your answer is considered correct if its absolute or relative error does not exceed $\textstyle 10^{-9}$. Formally, let your answer be $\textstyle a$, and the jury’s answer be $\textstyle b$. Your answer is accepted if and only if $\textstyle \frac{|a - b|}{\max(1, |b|)} \leq 10^{-9}$.

输入样例 复制

5
1 3 3 3
1 1 1 1
1 5 4 2
11 4 5 14
19 1 9 810

输出样例 复制

4
2
5.8309518948
18.8679622641
809.4844038028

数据范围与提示

In test case 3, the optimal path is:![](https://uploadfiles.nowcoder.com/images/20240711/0_1720677634515/75F60A0FC4890882425A751C4E49375D)