CF1623A.Robot Cleaner

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of nn rows and mm columns. The rows of the floor are numbered from 11 to nn from top to bottom, and columns of the floor are numbered from 11 to mm from left to right. The cell on the intersection of the rr-th row and the cc-th column is denoted as (r,c)(r,c). The initial position of the robot is (rb,cb)(r_b, c_b).

In one second, the robot moves by drdr rows and dcdc columns, that is, after one second, the robot moves from the cell (r,c)(r, c) to (r+dr,c+dc)(r + dr, c + dc). Initially dr=1dr = 1, dc=1dc = 1. If there is a vertical wall (the left or the right walls) in the movement direction, dcdc is reflected before the movement, so the new value of dcdc is −dc-dc. And if there is a horizontal wall (the upper or lower walls), drdr is reflected before the movement, so the new value of drdr is −dr-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 (rd,cd)(r_d, c_d). The job of the robot is to clean that dirty cell.

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 nn and mm, the robot's initial position (rb,cb)(r_b, c_b) and the dirty cell's position (rd,cd)(r_d, c_d), find the time for the robot to do its job.

一个机器人清洁器被放置在一个矩形房间的地板上,房间四周有墙壁。地板共有 nn 行和 mm 列。地板的行从上到下编号为 11 至 nn,列从左到右编号为 11 至 mm。第 rr 行与第 cc 列相交的格子记作 (r,c)(r,c)。机器人的初始位置为 (rb,cb)(r_b, c_b)。

每秒钟,机器人沿行方向移动 drdr 行、沿列方向移动 dcdc 列;即,一秒后,机器人从格子 (r,c)(r, c) 移动至 (r+dr,c+dc)(r + dr, c + dc)。初始时 dr=1dr = 1,dc=1dc = 1。若在移动方向上存在竖直墙壁(左侧或右侧墙壁),则在移动前将 dcdc 反射,即 dcdc 的新值变为 −dc-dc;若在移动方向上存在水平墙壁(上方或下方墙壁),则在移动前将 drdr 反射,即 drdr 的新值变为 −dr-dr。

每一秒(包括机器人开始移动前的初始时刻),机器人会清洁其所在位置的整行与整列上的所有格子。地板上仅有一个脏格子,位于 (rd,cd)(r_d, c_d)。机器人的任务是清洁该脏格子。

第一个样例的示意图。蓝色弧线表示机器人,红色星号表示目标脏格子。每一秒机器人清洁一行与一列,以黄色条带标出。

给定地板尺寸 nn 和 mm、机器人初始位置 (rb,cb)(r_b, c_b) 以及脏格子位置 (rd,cd)(r_d, c_d),求机器人完成任务所需的时间。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). Description of the test cases follows.

A test case consists of only one line, containing six integers nn, mm, rbr_b, cbc_b, rdr_d, and cdc_d (1≤n,m≤1001 \le n, m \le 100, 1≤rb,rd≤n1 \le r_b, r_d \le n, 1≤cb,cd≤m1 \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.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例仅占一行,包含六个整数 nn、mm、rbr_b、cbc_b、rdr_d 和 cdc_d(1≤n,m≤1001 \le n, m \le 100,1≤rb,rd≤n1 \le r_b, r_d \le n,1≤cb,cd≤m1 \le c_b, c_d \le m)——分别表示房间的尺寸、机器人初始位置以及脏污单元格的位置。

输出格式

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×1010\times 10. The initial position of the robot is (6,1)(6, 1) and the position of the dirty cell is (2,8)(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)(9, 9), and the position of the dirty cell is (1,1)(1, 1). In this example, the robot went straight to the dirty cell and clean it.

In the third example, the floor has the size 9×89 \times 8. The initial position of the robot is (5,6)(5, 6), and the position of the dirty cell is (2,1)(2, 1).

In the fourth example, the floor has the size 6×96 \times 9. The initial position of the robot is (2,2)(2, 2) and the position of the dirty cell is (5,8)(5, 8).

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.

在第一个例子中,地板的尺寸为 10×1010\times 10。机器人的初始位置为 (6,1)(6, 1),脏单元格的位置为 (2,8)(2, 8)。该例子的示意图见题目描述。

在第二个例子中,地板尺寸不变,但机器人的初始位置变为 (9,9)(9, 9),脏单元格的位置为 (1,1)(1, 1)。在此例中,机器人直接前往脏单元格并将其清洁。

在第三个例子中,地板的尺寸为 9×89 \times 8。机器人的初始位置为 (5,6)(5, 6),脏单元格的位置为 (2,1)(2, 1)。

在第四个例子中,地板的尺寸为 6×96 \times 9。机器人的初始位置为 (2,2)(2, 2),脏单元格的位置为 (5,8)(5, 8)。

在最后一个例子中,机器人已处于与脏单元格相同的列中,因此可立即清洁该单元格。

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

首页