CF1555B.Two Tables
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have an axis-aligned rectangle room with width W and height H, so the lower left corner is in point (0,0) and the upper right corner is in (W,H).
There is a rectangular table standing in this room. The sides of the table are parallel to the walls, the lower left corner is in (x1,y1), and the upper right corner in (x2,y2).
You want to place another rectangular table in this room with width w and height h with the width of the table parallel to the width of the room.
The problem is that sometimes there is not enough space to place the second table without intersecting with the first one (there are no problems with tables touching, though).
You can't rotate any of the tables, but you can move the first table inside the room.
Example of how you may move the first table.
What is the minimum distance you should move the first table to free enough space for the second one?
你有一个与坐标轴对齐的矩形房间,宽度为 W、高度为 H,因此其左下角位于点 (0,0),右上角位于 (W,H)。
房间内已放置一张矩形桌子。该桌子的边与墙壁平行,其左下角位于 (x1,y1),右上角位于 (x2,y2)。
你想在房间内再放置一张矩形桌子,其宽度为 w、高度为 h,且该桌子的宽度方向与房间的宽度方向平行。
问题在于,有时房间中没有足够的空间在不与第一张桌子相交的前提下放置第二张桌子(但两张桌子可以互相接触)。
你不能旋转任意一张桌子,但你可以在房间内移动第一张桌子。
第一张桌子可能的移动方式示例。
为了给第二张桌子腾出足够空间,你需要将第一张桌子移动的最小距离是多少?
输入格式
The first line contains the single integer t (1≤t≤5000) — the number of the test cases.
The first line of each test case contains two integers W and H (1≤W,H≤108) — the width and the height of the room.
The second line contains four integers x1, y1, x2 and y2 (0≤x1<x2≤W; 0≤y1<y2≤H) — the coordinates of the corners of the first table.
The third line contains two integers w and h (1≤w≤W; 1≤h≤H) — the width and the height of the second table.
第一行包含一个整数 t(1≤t≤5000)—— 测试用例的数量。
每个测试用例的第一行包含两个整数 W 和 H(1≤W,H≤108)—— 房间的宽度和高度。
每个测试用例的第二行包含四个整数 x1、y1、x2 和 y2(0≤x1<x2≤W;0≤y1<y2≤H)—— 第一张桌子两个对角顶点的坐标。
每个测试用例的第三行包含两个整数 w 和 h(1≤w≤W;1≤h≤H)—— 第二张桌子的宽度和高度。
输出格式
For each test case, print the minimum distance you should move the first table, or −1 if there is no way to free enough space for the second table.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10−6.
对于每个测试用例,输出你需要移动第一张桌子的最小距离;如果无法腾出足够空间放置第二张桌子,则输出 −1。
若你的答案的绝对或相对误差不超过 10−6,则视为正确。
输入输出样例
输入#1
5 8 5 2 1 7 4 4 2 5 4 2 2 5 4 3 3 1 8 0 3 1 6 1 5 8 1 3 0 6 1 5 1 8 10 4 5 7 8 8 5
输出#1
1.000000000 -1 2.000000000 2.000000000 0.000000000
说明/提示
The configuration of the first test case is shown in the picture. But the movement of the first table is not optimal. One of the optimal movement, for example, is to move the table by (0,−1), so the lower left corner will move from (2,1) to (2,0). Then you can place the second table at (0,3)−(4,5).
In the second test case, there is no way to fit both tables in the room without intersecting.
In the third test case, you can move the first table by (0,2), so the lower left corner will move from (0,3) to (0,5).
第一个测试用例的配置如图所示。但第一张桌子的移动方式并非最优。例如,一种最优的移动方式是将桌子沿向量 (0,−1) 移动,使得其左下角从 (2,1) 移动到 (2,0)。随后,你便可以将第二张桌子放置在区域 (0,3)−(4,5) 内。
在第二个测试用例中,无法在不使两张桌子相交的情况下将它们同时放入房间内。
在第三个测试用例中,你可以将第一张桌子沿向量 (0,2) 移动,使得其左下角从 (0,3) 移动到 (0,5)。
输入解题思路,AI测评打分。不知道怎么写?