A15670 | Li Hua and Maze
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is a rectangular maze of size $n\times m$ . Denote $(r,c)$ as the cell on the $r$ -th row from the top and the $c$ -th column from the left. Two cells are adjacent if they share an edge. A path is a sequence of adjacent empty cells.
Each cell is initially empty. Li Hua can choose some cells (except $(x_1, y_1)$ and $(x_2, y_2)$ ) and place an obstacle in each of them. He wants to know the minimum number of obstacles needed to be placed so that there isn't a path from $(x_1, y_1)$ to $(x_2, y_2)$ .
Suppose you were Li Hua, please solve this problem.
Each cell is initially empty. Li Hua can choose some cells (except $(x_1, y_1)$ and $(x_2, y_2)$ ) and place an obstacle in each of them. He wants to know the minimum number of obstacles needed to be placed so that there isn't a path from $(x_1, y_1)$ to $(x_2, y_2)$ .
Suppose you were Li Hua, please solve this problem.
输入格式
The first line contains the single integer $t$ ( $1 \le t \le 500$ ) — the number of test cases.
The first line of each test case contains two integers $n,m$ ( $4\le n,m\le 10^9$ ) — the size of the maze.
The second line of each test case contains four integers $x_1,y_1,x_2,y_2$ ( $1\le x_1,x_2\le n, 1\le y_1,y_2\le m$ ) — the coordinates of the start and the end.
It is guaranteed that $|x_1-x_2|+|y_1-y_2|\ge 2$ .
The first line of each test case contains two integers $n,m$ ( $4\le n,m\le 10^9$ ) — the size of the maze.
The second line of each test case contains four integers $x_1,y_1,x_2,y_2$ ( $1\le x_1,x_2\le n, 1\le y_1,y_2\le m$ ) — the coordinates of the start and the end.
It is guaranteed that $|x_1-x_2|+|y_1-y_2|\ge 2$ .
输出格式
For each test case print the minimum number of obstacles you need to put on the field so that there is no path from $(x_1, y_1)$ to $(x_2, y_2)$ .
输入输出样例
输入 #1
3 4 4 2 2 3 3 6 7 1 1 2 3 9 9 5 1 3 6
输出 #1
4 2 3
In test case 1, you can put obstacles on $(1,3), (2,3), (3,2), (4,2)$ . Then the path from $(2,2)$ to $(3,3)$ will not exist.


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted