QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#7965. 机器人

Statistics

题目描述

有 $n$ 个机器人围成一圈,编号按照逆时针顺序分别为 $0\sim n-1$。

每个机器人有两只手。编号为 $i$ 的机器人初始「左手」指向编号 $l_i$ 的机器人,「右手」指向编号 $r_i$ 的机器人。

所有的机器人内部都写有 $m$ 行「指令」,「指令」有以下这些形式:

指令

「指令」分为「基础指令」和「高级指令」两种。「高级指令」的功能会更复杂一些,但它们本质上没有多大区别。下面介绍这些「指令」的格式以及它们被「执行」时的效果。文中的“自己”一词均指拥有这条「指令」的机器人。

基础指令

  • SLACKOFF「摸鱼」,即什么也不做。
  • MOVE h z:将第 $h$ 只手向逆时针方向「移动」$z$ 个机器人的位置。当 $h=0$ 时表示「左手」,当 $h=1$ 时表示「右手」,下同。
  • SWAP h x y:将第 $h$ 只手指向的机器人的第 $x$ 行「指令」与自己的第 $y$ 行「指令」「对调」
  • MIRROR h x:将第 $h$ 只手指向的机器人的第 $x$ 行「指令」「镜像」取反,即将「指令」中的 $h$ 取反($0$ 变成 $1$,$1$ 变成 $0$)。特殊地,它对 SLACKOFF 指令没有效果;而对 TRIGGER 指令,会直接修改「触发」时「执行」的「指令」中的 $h$。
  • REPLACE h x <COMMAND>:将第 $h$ 只手指向的机器人的第 $x$ 行「指令」「替换」<COMMAND>。其中 <COMMAND> 为一条完整的「指令」。

高级指令

  • ACTIVATE h「激活」第 $h$ 只手指向的机器人,即按顺序「执行」那个机器人的所有「指令」。前一行「指令」「执行」完毕之后才会「执行」后一行。注意在「执行」前面的「指令」时后面的「指令」可能会发生更改,这时需要「执行」更改后的「指令」。当那个机器人的所有「指令」「执行」完毕后,该「指令」才算「执行」完毕。
  • TRIGGER <COMMANDNAME>: <COMMAND>:其中 <COMMANDNAME> 表示「指令」的名称,即一条「指令」中的第一个全大写单词;<COMMAND> 表示一条完整的「基础指令」。TRIGGER 指令不会被「执行」,即按顺序「执行」时会跳过该「指令」。但是,当一个其他机器人「执行」完一条「指令」之后,且「右手」指向自己的时候,自己最靠前的满足如下条件的 TRIGGER 指令(如果有)就会被「触发」——「执行」一次对应的 <COMMAND>

    • <COMMANDNAME> 不为 TRIGGER 时,刚刚「执行」完毕的「指令」为 <COMMANDNAME> 指令;
    • <COMMANDNAME>TRIGGER 时,刚刚「执行」完毕的「指令」是 TRIGGER 指令被「触发」时「执行」的「指令」。

    「执行」完毕后会回到原来的「执行」顺序中。

你需要从 $0$ 号机器人开始按照编号顺序一圈又一圈地「激活」这些机器人,并输出「执行」的前 $k$ 条指令的有关信息。

输入格式

从标准输入读入数据。

第一行三个正整数 $n,m,k$。

接下来按照编号从小到大的顺序表示 $n$ 个机器人的信息。

对于每个机器人,第一行两个非负整数 $l_i,r_i$ 表示「左手」指向的机器人编号和「右手」指向的机器人编号。

接下来 $m$ 行,按顺序表示机器人的「指令」,「指令」的格式见题目描述。

输出格式

输出到标准输出。

输出 $k$ 行,按顺序描述前 $k$ 条开始「执行」的指令的相关信息,在开始「执行」前输出,每条一行,格式如下:

  • 「摸鱼」时输出 Robot <id> slacks off.。其中 <id> 为一个整数,表示「执行」当前「指令」的机器人编号,下同。
  • 「移动」时输出 Robot <id> moves its <side> hand towards Robot <id2>.。其中 <side>leftright,表示移动了哪只手(left 表示「左手」,right 表示「右手」);<id2> 为一个整数,表示移动之后这只手指向的机器人的编号。
  • 「对调」时输出 Robot <id> swaps a line of command with Robot <id2>.。其中 <id2> 为一个整数,表示与之「对调」「指令」的机器人编号。
  • 「镜像」取反时输出 Robot <id> modifies a line of command of Robot <id2>.。其中 <id2> 为一个整数,表示被「镜像」取反「指令」的机器人编号。
  • 「替换」时输出 Robot <id> replaces a line of command of Robot <id2>.。其中 <id2> 为一个整数,表示被「替换」「指令」的机器人编号。
  • 「执行」 ACTIVATE 指令「激活」(区别于你的一圈又一圈的「激活」)时输出 Robot <id> activates Robot <id2>.。其中 <id2> 为一个整数,表示被「激活」的机器人编号。
  • TRIGGER 指令由于不会被「执行」就不需要输出,但当它们被「触发」时,仍然需要按照上面的格式输出对应的「基础指令」被「执行」的信息。

样例1输入

2 2 5
0 0
MOVE 1 1
MOVE 0 1
0 1
TRIGGER MOVE: MOVE 0 1
SLACKOFF

样例1输出

Robot 0 moves its right hand towards Robot 1.
Robot 1 moves its left hand towards Robot 1.
Robot 0 moves its left hand towards Robot 1.
Robot 1 moves its left hand towards Robot 0.
Robot 1 slacks off.

样例1解释

TRIGGER 指令的「触发」时机是「执行」完毕之后。注意不能「触发」自己的 TRIGGER 指令。

样例2输入

2 2 4
0 1
ACTIVATE 1
SLACKOFF
0 1
SWAP 0 2 2
MIRROR 0 1

样例2输出

Robot 0 activates Robot 1.
Robot 1 swaps a line of command with Robot 0.
Robot 1 slacks off.
Robot 0 modifies a line of command of Robot 0.

样例2解释

注意在「执行」前面的「指令」时后面的「指令」可能会发生更改,这时需要「执行」更改后的「指令」。

样例3输入

3 2 6
1 2
ACTIVATE 0
ACTIVATE 0
2 1
SWAP 0 2 2
TRIGGER ACTIVATE: REPLACE 0 2 SLACKOFF
0 1
TRIGGER MIRROR: SLACKOFF
SLACKOFF

样例3输出

Robot 0 activates Robot 1.
Robot 1 swaps a line of command with Robot 2.
Robot 1 slacks off.
Robot 2 replaces a line of command of Robot 0.
Robot 0 slacks off.
Robot 1 swaps a line of command with Robot 2.

样例3解释

ACTIVATE 指令「激活」另一个机器人时,当那个机器人的所有「指令」「执行」完毕后,该「指令」才算「执行」完毕。

样例4输入

3 2 8
0 1
SLACKOFF
TRIGGER MOVE: SLACKOFF
1 2
TRIGGER TRIGGER: SLACKOFF
TRIGGER SLACKOFF: MOVE 0 1
2 0
TRIGGER SLACKOFF: MOVE 1 2
TRIGGER TRIGGER: MOVE 1 1

样例4输出

Robot 0 slacks off.
Robot 1 moves its left hand towards Robot 2.
Robot 2 moves its right hand towards Robot 1.
Robot 1 slacks off.
Robot 2 moves its right hand towards Robot 0.
Robot 0 slacks off.
Robot 1 slacks off.
Robot 2 moves its right hand towards Robot 2.

样例4解释

只有自己最靠前的满足条件的 TRIGGER 指令才会被「触发」

样例5

见题目目录下的 5.in5.ans

样例5解释

无私的馈赠?有力的援助?

子任务

保证所有的指令的格式均正确。

保证输入文件的长度不超过 $5\mathtt{MB}$。

保证能够「执行」至少 $k$ 条「指令」。

保证 $2\le n\le 100$,$1\le m \le 10$,$1\le k \le 3\times 10^5$。

保证 $0\le l_i,r_i < n$。

保证 $0\le h \le 1$,$1\le x,y \le m$,$1\le z < n$。所有输入的数都是整数。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.