#abc335c. C - Loong Tracking
C - Loong Tracking
Score : points
问题描述
高桥创造了一个游戏,玩家在游戏中控制坐标平面上的一条龙。
这条龙由 个部分组成,编号从 到 ,其中第 个部分被称为 头部。
初始状态下,第 个部分位于坐标 。处理 个查询,如下所示。
1 C
:在方向 上将头部移动 个单位。这里, 可以是R
、L
、U
或D
,分别代表正 轴方向、负 轴方向、正 轴方向和负 轴方向。除了头部以外的每个部分都会跟随其前面的部分移动。即,第 个部分()会移动到移动前第 个部分所在的位置。2 p
:找出第 个部分的坐标。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has created a game where the player controls a dragon on a coordinate plane.
The dragon consists of parts numbered to , with part being called the head.
Initially, part is located at the coordinates . Process queries as follows.
1 C
: Move the head by in direction . Here, is one ofR
,L
,U
, andD
, which represent the positive -direction, negative -direction, positive -direction, and negative -direction, respectively. Each part other than the head moves to follow the part in front of it. That is, part moves to the coordinates where part was before the move.2 p
: Find the coordinates of part .
Constraints
- For the first type of query, is one of
R
,L
,U
, andD
. - For the second type of query, .
- All numerical input values are integers.
Input
The input is given from Standard Input in the following format:
Each query is in one of the following two formats:
Output
Print lines, where is the number of queries of the second type.
The -th line should contain and separated by a space, where are the answer to the -th such query.
Sample Input 1
5 9
2 3
1 U
2 3
1 R
1 D
2 3
1 L
2 1
2 5
Sample Output 1
3 0
2 0
1 1
1 0
1 0
At each time when processing the second type of query, the parts are at the following positions:
Note that multiple parts may exist at the same coordinates.
update @ 2024/3/10 01:23:23