309092: CF1623A. Robot Cleaner

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Robot Cleaner

题意翻译

你住在一个 $n$ 行 $m$ 列的矩形房间里,令这个房间里面的第 $x$ 行第 $y$ 列为 $(x,y)$。有一天,你站在位置 $(r_b,c_b)$ 上,就在这时,你发现在位置 $(r_d,c_d)$ 上有一粒灰尘。于是你拿出了你最近发明的的扫地机器人准备清扫这粒灰尘。这个机器人会从你的位置开始出发,在一步以内可以从 $(r,c)$ 移动到 $(r+dr,c+dc)$。一开始,$dr=dc=1$。然而,你知道如果让机器人一直这么移动,它会撞上墙壁。于是,你在程序里面设定:如果机器人继续移动一步会撞上这个房间左边或者右边的墙壁,那么 $dc=-dc$;如果机器人继续移动一步会撞上这个房间上面或者下面的墙壁,那么 $dr=-dr$。在每开始移动一步之前,这个机器人会把它所在的行和列上的所有灰尘全部清除。 你现在想知道,如果机器人按照如上方式移动,需要多少步才能将在位置 $(r_d,c_d)$ 上的那粒灰尘清除。 数据范围: - $t$ 组数据,$1\leqslant t\leqslant 10^4$。 - $1\leqslant n,m\leqslant 100$。$1\leqslant r_b,r_d\leqslant n$,$1\leqslant c_b,c_d\leqslant m$。 Translated by Eason_AC 2021.12.29

题目描述

A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of $ n $ rows and $ m $ columns. The rows of the floor are numbered from $ 1 $ to $ n $ from top to bottom, and columns of the floor are numbered from $ 1 $ to $ m $ from left to right. The cell on the intersection of the $ r $ -th row and the $ c $ -th column is denoted as $ (r,c) $ . The initial position of the robot is $ (r_b, c_b) $ . In one second, the robot moves by $ dr $ rows and $ dc $ columns, that is, after one second, the robot moves from the cell $ (r, c) $ to $ (r + dr, c + dc) $ . Initially $ dr = 1 $ , $ dc = 1 $ . If there is a vertical wall (the left or the right walls) in the movement direction, $ dc $ is reflected before the movement, so the new value of $ dc $ is $ -dc $ . And if there is a horizontal wall (the upper or lower walls), $ dr $ is reflected before the movement, so the new value of $ dr $ is $ -dr $ . Each second (including the moment before the robot starts moving), the robot cleans every cell lying in the same row or the same column as its position. There is only one dirty cell at $ (r_d, c_d) $ . The job of the robot is to clean that dirty cell. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1623A/353cecd0655788f0456756b617e53c4b27217e92.png)Illustration for the first example. The blue arc is the robot. The red star is the target dirty cell. Each second the robot cleans a row and a column, denoted by yellow stripes.Given the floor size $ n $ and $ m $ , the robot's initial position $ (r_b, c_b) $ and the dirty cell's position $ (r_d, c_d) $ , find the time for the robot to do its job.

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^4 $ ). Description of the test cases follows. A test case consists of only one line, containing six integers $ n $ , $ m $ , $ r_b $ , $ c_b $ , $ r_d $ , and $ c_d $ ( $ 1 \le n, m \le 100 $ , $ 1 \le r_b, r_d \le n $ , $ 1 \le c_b, c_d \le m $ ) — the sizes of the room, the initial position of the robot and the position of the dirt cell.

输出格式


For each test case, print an integer — the time for the robot to clean the dirty cell. We can show that the robot always cleans the dirty cell eventually.

输入输出样例

输入样例 #1

5
10 10 6 1 2 8
10 10 9 9 1 1
9 8 5 6 2 1
6 9 2 2 5 8
2 2 1 1 2 1

输出样例 #1

7
10
9
3
0

说明

In the first example, the floor has the size of $ 10\times 10 $ . The initial position of the robot is $ (6, 1) $ and the position of the dirty cell is $ (2, 8) $ . See the illustration of this example in the problem statement. In the second example, the floor is the same, but the initial position of the robot is now $ (9, 9) $ , and the position of the dirty cell is $ (1, 1) $ . In this example, the robot went straight to the dirty cell and clean it. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1623A/353cecd0655788f0456756b617e53c4b27217e92.png)In the third example, the floor has the size $ 9 \times 8 $ . The initial position of the robot is $ (5, 6) $ , and the position of the dirty cell is $ (2, 1) $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1623A/739ff7881b31dac6b032f49a1d030ea2239cce23.png)In the fourth example, the floor has the size $ 6 \times 9 $ . The initial position of the robot is $ (2, 2) $ and the position of the dirty cell is $ (5, 8) $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1623A/894677a107944433f0765cac55f3b1894977a3b1.png)In the last example, the robot was already standing in the same column as the dirty cell, so it can clean the cell right away. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1623A/63428259d37d691365ae24c739cf43777cc8eec7.png)

Input

题意翻译

你住在一个 $n$ 行 $m$ 列的矩形房间里,令这个房间里面的第 $x$ 行第 $y$ 列为 $(x,y)$。有一天,你站在位置 $(r_b,c_b)$ 上,就在这时,你发现在位置 $(r_d,c_d)$ 上有一粒灰尘。于是你拿出了你最近发明的的扫地机器人准备清扫这粒灰尘。这个机器人会从你的位置开始出发,在一步以内可以从 $(r,c)$ 移动到 $(r+dr,c+dc)$。一开始,$dr=dc=1$。然而,你知道如果让机器人一直这么移动,它会撞上墙壁。于是,你在程序里面设定:如果机器人继续移动一步会撞上这个房间左边或者右边的墙壁,那么 $dc=-dc$;如果机器人继续移动一步会撞上这个房间上面或者下面的墙壁,那么 $dr=-dr$。在每开始移动一步之前,这个机器人会把它所在的行和列上的所有灰尘全部清除。 你现在想知道,如果机器人按照如上方式移动,需要多少步才能将在位置 $(r_d,c_d)$ 上的那粒灰尘清除。 数据范围: - $t$ 组数据,$1\leqslant t\leqslant 10^4$。 - $1\leqslant n,m\leqslant 100$。$1\leqslant r_b,r_d\leqslant n$,$1\leqslant c_b,c_d\leqslant m$。 Translated by Eason_AC 2021.12.29

加入题单

算法标签: