CF1547A.Shortest Path with Obstacle

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There are three cells on an infinite 2-dimensional grid, labeled AA, BB, and FF. Find the length of the shortest path from AA to BB if:

  • in one move you can go to any of the four adjacent cells sharing a side;
  • visiting the cell FF is forbidden (it is an obstacle).

在一个无限的二维网格上有三个格子,标记为 AA、BB 和 FF。求从 AA 到 BB 的最短路径长度,要求满足:

  • 每次移动可到达上下左右四个相邻(共享一条边)的格子之一;
  • 禁止经过格子 FF(它是一个障碍物)。

输入格式

The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases in the input. Then tt test cases follow. Before each test case, there is an empty line.

Each test case contains three lines. The first one contains two integers xA,yAx_A, y_A (1≤xA,yA≤10001 \le x_A, y_A \le 1000) — coordinates of the start cell AA. The second one contains two integers xB,yBx_B, y_B (1≤xB,yB≤10001 \le x_B, y_B \le 1000) — coordinates of the finish cell BB. The third one contains two integers xF,yFx_F, y_F (1≤xF,yF≤10001 \le x_F, y_F \le 1000) — coordinates of the forbidden cell FF. All cells are distinct.

Coordinate xx corresponds to the column number and coordinate yy corresponds to the row number (see the pictures below).

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 输入中测试用例的数量。随后是 tt 个测试用例。每个测试用例之前有一空行。

每个测试用例包含三行。第一行包含两个整数 xA,yAx_A, y_A(1≤xA,yA≤10001 \le x_A, y_A \le 1000)—— 起始格子 AA 的坐标;第二行包含两个整数 xB,yBx_B, y_B(1≤xB,yB≤10001 \le x_B, y_B \le 1000)—— 终止格子 BB 的坐标;第三行包含两个整数 xF,yFx_F, y_F(1≤xF,yF≤10001 \le x_F, y_F \le 1000)—— 禁止通行格子 FF 的坐标。所有格子互不相同。

坐标 xx 对应列号,坐标 yy 对应行号(参见下方图片)。

输出格式

Output tt lines. The ii-th line should contain the answer for the ii-th test case: the length of the shortest path from the cell AA to the cell BB if the cell FF is not allowed to be visited.

输出 tt 行。第 ii 行应包含第 ii 个测试用例的答案:即从单元格 AA 到单元格 BB 的最短路径长度(禁止经过单元格 FF)。

输入输出样例

  • 输入#1

    7
    
    1 1
    3 3
    2 2
    
    2 5
    2 1
    2 3
    
    1000 42
    1000 1
    1000 1000
    
    1 10
    3 10
    2 10
    
    3 8
    7 8
    3 7
    
    2 1
    4 1
    1 1
    
    1 344
    1 10
    1 1

    输出#1

    4
    6
    41
    4
    4
    2
    334

说明/提示

An example of a possible shortest path for the first test case.

An example of a possible shortest path for the second test case.

第一个测试用例中一条可能的最短路径示例。

第二个测试用例中一条可能的最短路径示例。

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

首页