308116: CF1468K. The Robot

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

The Robot

题意翻译

### 题目描述 在一个无尽的原野上有一个机器人,开始时它位于 $(0,0)$,它将执行一个由 L,R,D,U 四种命令组成的序列,当一个命令被执行时,机器人会向这个命令指定的方向移动一格: * L : 向左移动一格。($x$ 减一) * R : 向右移动一格。($x$ 加一) * D : 向下移动一格。($y$ 减一) * U : 向上移动一格。($y$ 加一) 你的任务是在一个格子中放置一个障碍物,使机器人在执行完命令后恰好在 $(0,0)$。当然,你不能将障碍物放在 $(0,0)$ 上。 注:数据保证若你不放置障碍物,机器人执行完命令后将不会停在 $(0,0)$。 若机器人移动后的格子有障碍物,障碍物会阻止机器人行动,机器人会留在原地同时障碍物也不会消失。 请你找出一个不是 $(0,0)$ 的格子放置障碍物,使机器人能返回 $(0,0)$,若无法达成目标,请输出一个特定的答案。(见输出格式) ### 输入格式 第一行一个整数 $t$,表示数据组数。 接下来有 $t$ 行,每行一个长度不超过 $5000$ 不小于 $1$ 的字符串 $s$ 表示当前测试点的命令序列, 这个序列仅有 L,R,D,U 组成,并且保证若你不放置障碍物,机器人执行完命令后将不会停在 $(0,0)$。 所有 $s$ 长度之和不超过 $5000$。 ### 输出格式 对于每个测试点输出一行: * 若存在一种方案,输出障碍物的坐标 $(x,y)$,数据保证 $-10^9 \le x,y \le 10^9$。 * 若不存在方案,输出 $(0,0)$。 * 若有多组解,输出任意一组即可。

题目描述

There is a robot on a checkered field that is endless in all directions. Initially, the robot is located in the cell with coordinates $ (0, 0) $ . He will execute commands which are described by a string of capital Latin letters 'L', 'R', 'D', 'U'. When a command is executed, the robot simply moves in the corresponding direction: - 'L': one cell to the left (the $ x $ -coordinate of the current cell decreases by $ 1 $ ); - 'R': one cell to the right (the $ x $ -coordinate of the current cell is increased by $ 1 $ ); - 'D': one cell down (the $ y $ -coordinate of the current cell decreases by $ 1 $ ); - 'U': one cell up (the $ y $ -coordinate of the current cell is increased by $ 1 $ ). Your task is to put an obstacle in one cell of the field so that after executing the commands, the robot will return to the original cell of its path $ (0, 0) $ . Of course, an obstacle cannot be placed in the starting cell $ (0, 0) $ . It is guaranteed that if the obstacle is not placed, then the robot will not return to the starting cell. An obstacle affects the movement of the robot in the following way: if it tries to go in a certain direction, and there is an obstacle, then it simply remains in place (the obstacle also remains, that is, it does not disappear). Find any such cell of the field (other than $ (0, 0) $ ) that if you put an obstacle there, the robot will return to the cell $ (0, 0) $ after the execution of all commands. If there is no solution, then report it.

输入输出格式

输入格式


The first line contains one integer $ t $ ( $ 1 \le t \le 500 $ ) — the number of test cases. Each test case consists of a single line containing $ s $ — the sequence of commands, which are uppercase Latin letters 'L', 'R', 'D', 'U' only. The length of $ s $ is between $ 1 $ and $ 5000 $ , inclusive. Additional constraint on $ s $ : executing this sequence of commands leads the robot to some cell other than $ (0, 0) $ , if there are no obstacles. The sum of lengths of all $ s $ in a test doesn't exceed $ 5000 $ .

输出格式


For each test case print a single line: - if there is a solution, print two integers $ x $ and $ y $ ( $ -10^9 \le x,y \le 10^9 $ ) such that an obstacle in $ (x, y) $ will force the robot to return back to the cell $ (0, 0) $ ; - otherwise, print two zeroes (i. e. 0 0). If there are multiple answers, you can print any of them.

输入输出样例

输入样例 #1

4
L
RUUDL
LLUU
DDDUUUUU

输出样例 #1

-1 0
1 2
0 0
0 1

Input

题意翻译

### 题目描述 在一个无尽的原野上有一个机器人,开始时它位于 $(0,0)$,它将执行一个由 L,R,D,U 四种命令组成的序列,当一个命令被执行时,机器人会向这个命令指定的方向移动一格: * L : 向左移动一格。($x$ 减一) * R : 向右移动一格。($x$ 加一) * D : 向下移动一格。($y$ 减一) * U : 向上移动一格。($y$ 加一) 你的任务是在一个格子中放置一个障碍物,使机器人在执行完命令后恰好在 $(0,0)$。当然,你不能将障碍物放在 $(0,0)$ 上。 注:数据保证若你不放置障碍物,机器人执行完命令后将不会停在 $(0,0)$。 若机器人移动后的格子有障碍物,障碍物会阻止机器人行动,机器人会留在原地同时障碍物也不会消失。 请你找出一个不是 $(0,0)$ 的格子放置障碍物,使机器人能返回 $(0,0)$,若无法达成目标,请输出一个特定的答案。(见输出格式) ### 输入格式 第一行一个整数 $t$,表示数据组数。 接下来有 $t$ 行,每行一个长度不超过 $5000$ 不小于 $1$ 的字符串 $s$ 表示当前测试点的命令序列, 这个序列仅有 L,R,D,U 组成,并且保证若你不放置障碍物,机器人执行完命令后将不会停在 $(0,0)$。 所有 $s$ 长度之和不超过 $5000$。 ### 输出格式 对于每个测试点输出一行: * 若存在一种方案,输出障碍物的坐标 $(x,y)$,数据保证 $-10^9 \le x,y \le 10^9$。 * 若不存在方案,输出 $(0,0)$。 * 若有多组解,输出任意一组即可。

加入题单

算法标签: