CF1781A.Parallel Projection

入门

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vika's house has a room in a shape of a rectangular parallelepiped (also known as a rectangular cuboid). Its floor is a rectangle of size w×dw \times d, and the ceiling is right above at the constant height of hh. Let's introduce a coordinate system on the floor so that its corners are at points (0,0)(0, 0), (w,0)(w, 0), (w,d)(w, d), and (0,d)(0, d).

A laptop is standing on the floor at point (a,b)(a, b). A projector is hanging on the ceiling right above point (f,g)(f, g). Vika wants to connect the laptop and the projector with a cable in such a way that the cable always goes along the walls, ceiling, or floor (i. e. does not go inside the cuboid). Additionally, the cable should always run parallel to one of the cuboid's edges (i. e. it can not go diagonally).

What is the minimum length of a cable that can connect the laptop to the projector?

Illustration for the first test case. One of the optimal ways to put the cable is shown in green.

维卡的房间是一个长方体(也称为矩形棱柱)。其地面是一个 w×dw \times d 的矩形,天花板位于地面上方恒定高度 hh 处。我们在地面上建立一个坐标系,使得地面四个角的坐标分别为 (0,0)(0, 0)、(w,0)(w, 0)、(w,d)(w, d) 和 (0,d)(0, d)。

一台笔记本电脑放置在地面上的点 (a,b)(a, b) 处,一台投影仪悬挂在天花板上、正对着点 (f,g)(f, g) 的位置。维卡希望用一根电缆将笔记本电脑与投影仪连接起来,且电缆必须始终沿墙壁、天花板或地面铺设(即不能穿过长方体内部)。此外,电缆必须始终平行于长方体的某一条棱(即不允许走对角线)。

连接笔记本电脑与投影仪所需的电缆的最短长度是多少?

第一个测试用例的示意图。图中绿色路径即为一种最优布线方式。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains three integers ww, dd, and hh (2≤w,d,h≤10002 \le w, d, h \le 1000) — the size of the room.

The second line contains four integers aa, bb, ff, gg (0<a,f<w0 \lt a, f \lt w; 0<b,g<d0 \lt b, g \lt d): the laptop is located on the floor at point (a,b)(a, b), while the projector is hanging on the ceiling right above point (f,g)(f, g).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 ww、dd 和 hh(2≤w,d,h≤10002 \le w, d, h \le 1000)——表示房间的尺寸。

每个测试用例的第二行包含四个整数 aa、bb、ff、gg(0<a,f<w0 \lt a, f \lt w;0<b,g<d0 \lt b, g \lt d):笔记本电脑位于地板上的点 (a,b)(a, b) 处,而投影仪悬挂在天花板上,正位于点 (f,g)(f, g) 的正上方。

输出格式

For each test case, print a single integer — the minimum length of the cable connecting the laptop and the projector that runs only along the walls, floor, and ceiling parallel to cuboid's edges.

对于每个测试用例,输出一个整数——即仅沿墙壁、地板和天花板(且平行于长方体的棱)铺设的连接笔记本电脑与投影仪的电缆的最短长度。

输入输出样例

  • 输入#1

    5
    55 20 29
    23 10 18 3
    20 10 5
    1 5 2 5
    15 15 4
    7 13 10 10
    2 1000 2
    1 1 1 999
    10 4 10
    7 1 2 1

    输出#1

    47
    8
    14
    1002
    17

说明/提示

The picture in the statement illustrates the first test case.

题目描述中的图片展示了第一个测试用例。

输入解题思路,AI测评打分。不知道怎么写?

首页