CF1332A.Exercising Walk
普及-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
- exactly a steps left: from (u,v) to (u−1,v);
- exactly b steps right: from (u,v) to (u+1,v);
- exactly c steps down: from (u,v) to (u,v−1);
- exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x1,x2]×[y1,y2], i.e. for every cat's position (u,v) of a walk x1≤u≤x2 and y1≤v≤y2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u,v) should always satisfy the constraints: x1≤u≤x2, y1≤v≤y2. The staring point is (x,y).
You are required to answer t test cases independently.
爱丽丝有一只可爱的猫。为了保持猫的身体健康,爱丽丝想为她的猫设计一次锻炼散步!
最初,爱丽丝的猫位于无限网格中的某个格子 (x,y) 上。根据爱丽丝的理论,猫需要恰好执行以下移动:
- 向左移动 a 步:从 (u,v) 移动到 (u−1,v);
- 向右移动 b 步:从 (u,v) 移动到 (u+1,v);
- 向下移动 c 步:从 (u,v) 移动到 (u,v−1);
- 向上移动 d 步:从 (u,v) 移动到 (u,v+1)。
注意:这些移动可以以任意顺序执行。例如,若猫需向左走 1 步、向右走 3 步、向下走 2 步,则路径“右、下、左、右、右、下”是合法的。
然而,爱丽丝担心猫若离她太远可能会迷路。因此,她希望猫在整个散步过程中始终处于区域 [x1,x2]×[y1,y2] 内,即对于散步中猫的每一个位置 (u,v),均满足 x1≤u≤x2 且 y1≤v≤y2。
另外请注意,猫可以多次访问同一格子。
你能帮爱丽丝判断是否存在一条满足她所有要求的散步路径吗?
形式化地说,该散步路径应恰好包含 a+b+c+d 个单位移动(其中 a 次向左、b 次向右、c 次向下、d 次向上)。爱丽丝可以按任意顺序执行这些移动。在散步过程中的任意时刻,猫的位置 (u,v) 都必须满足约束:x1≤u≤x2 且 y1≤v≤y2。起始位置为 (x,y)。
你需要独立地回答 t 组测试用例。
输入格式
The first line contains a single integer t (1≤t≤103) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0≤a,b,c,d≤108, a+b+c+d≥1).
The second line of the test case contains six integers x, y, x1, y1, x2, y2 (−108≤x1≤x≤x2≤108, −108≤y1≤y≤y2≤108).
第一行包含一个整数 t(1≤t≤103)——测试用例的数量。
每个测试用例的第一行包含四个整数 a、b、c、d(0≤a,b,c,d≤108,且 a+b+c+d≥1)。
每个测试用例的第二行包含六个整数 x、y、x1、y1、x2、y2(满足 −108≤x1≤x≤x2≤108,−108≤y1≤y≤y2≤108)。
输出格式
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
对于每个测试用例,如果存在一条满足她愿望的路径,则在单独一行输出 “YES”;否则,在单独一行输出 “NO”。
你可以以任意大小写(大写或小写)输出每个字母。
输入输出样例
输入#1
6 3 2 2 2 0 0 -2 -2 2 2 3 1 4 1 0 0 -1 -1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 0 0 0 1 5 1 1 1 0 0 -100 -100 0 100 1 1 5 1 0 0 -100 -100 100 0
输出#1
Yes No No Yes Yes Yes
说明/提示
In the first test case, one valid exercising walk is $$(0,0)\rightarrow (-1,0) \rightarrow (-2,0)\rightarrow (-2,1) \rightarrow (-2,2)\rightarrow (-1,2)\rightarrow(0,2)\rightarrow (0,1)\rightarrow (0,0) \rightarrow (-1,0)$$
在第一个测试用例中,一个有效的锻炼路径是
(0,0)→(−1,0)→(−2,0)→(−2,1)→(−2,2)→(−1,2)→(0,2)→(0,1)→(0,0)→(−1,0)
输入解题思路,AI测评打分。不知道怎么写?