RT,我无语了。
只 T #51 1.04s,这个点是 REPLACE 一直嵌套,我估计是读入和输出的问题,但是我懒得改了,所以有没有什么别的办法(((
#include<bits/stdc++.h>
using namespace std;
const int MaxRobot=105,MaxCommand=15,MaxMemory=1e7;
enum CommandType{
SLACKOFF,
MOVE,
SWAP,
MIRROR,
REPLACE,
ACTIVATE,
TRIGGER
};
struct Command{
CommandType type;
int h,x,y;
CommandType TRItype;
int pointcmd;
}command[MaxMemory];
int memoryCount=0;
struct Robot{
int h[2];
Command command[MaxCommand];
}robot[MaxRobot];
int n,m,k;
void doActivate(Robot &rbt,int rid);
void doCommand(Robot &rbt,int rid,Command &cmd,bool fromTrigger);
istream& operator >>(istream &in,Command &cmd){
string s;
in>>s;
if(s=="SLACKOFF"){
cmd.type=SLACKOFF;
}else if(s=="MOVE"){
cmd.type=MOVE;
in>>cmd.h>>cmd.x;
}else if(s=="SWAP"){
cmd.type=SWAP;
in>>cmd.h>>cmd.x>>cmd.y;
}else if(s=="MIRROR"){
cmd.type=MIRROR;
in>>cmd.h>>cmd.x;
}else if(s=="REPLACE"){
cmd.type=REPLACE;
in>>cmd.h>>cmd.x;
cmd.pointcmd=++memoryCount;
in>>command[memoryCount];
}else if(s=="ACTIVATE"){
cmd.type=ACTIVATE;
in>>cmd.h;
}else if(s=="TRIGGER"){
cmd.type=TRIGGER;
in>>s;s.pop_back();
if(s=="SLACKOFF"){
cmd.TRItype=SLACKOFF;
}else if(s=="MOVE"){
cmd.TRItype=MOVE;
}else if(s=="SWAP"){
cmd.TRItype=SWAP;
}else if(s=="MIRROR"){
cmd.TRItype=MIRROR;
}else if(s=="REPLACE"){
cmd.TRItype=REPLACE;
}else if(s=="ACTIVATE"){
cmd.TRItype=ACTIVATE;
}else if(s=="TRIGGER"){
cmd.TRItype=TRIGGER;
}
cmd.pointcmd=++memoryCount;
in>>command[memoryCount];
}
return in;
}
istream& operator >>(istream &in,Robot &rbt){
in>>rbt.h[0]>>rbt.h[1];
for(int i=1;i<=m;i++){
in>>rbt.command[i];
}
return in;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m>>k;
for(int i=0;i<n;i++){
cin>>robot[i];
}
while(1){
for(int i=0;i<n;i++){
doActivate(robot[i],i);
}
}
cout<<"Run Over.";
return 0;
}
void doActivate(Robot &rbt,int rid){
for(int i=1;i<=m;i++){
doCommand(rbt,rid,rbt.command[i],0);
}
}
void Mirror(int &pointcmd){
if(command[pointcmd].type==SLACKOFF){
return;
}
command[++memoryCount]=command[pointcmd];
pointcmd=memoryCount;
if(command[pointcmd].type!=TRIGGER){
command[pointcmd].h^=1;
}else{
Mirror(command[pointcmd].pointcmd);
}
}
void Mirror(Command &cmd){
if(cmd.type!=TRIGGER){
cmd.h^=1;
}
else{
Mirror(cmd.pointcmd);
}
}
void doTrigger(Robot &rbt,int rid,CommandType cmd_t,bool fromTrigger){
for(int i=1;i<=m;i++){
Command &cmd=rbt.command[i];
if(cmd.type==TRIGGER){
if(cmd.TRItype!=TRIGGER){
if(cmd.TRItype==cmd_t){
doCommand(rbt,rid,command[cmd.pointcmd],1);
return;
}
}else if(fromTrigger==true){
doCommand(rbt,rid,command[cmd.pointcmd],1);
return;
}
}
}
}
void doCommand(Robot &rbt,int rid,Command &cmd,bool fromTrigger=0){
if(k==0)exit(0);
if(cmd.type==TRIGGER)return;
k--;
CommandType cmdcpy=cmd.type;
if(cmd.type==SLACKOFF){
cout<<"Robot "<<rid<<" slacks off.\n";
}else if(cmd.type==MOVE){
cout<<"Robot "<<rid<<" moves its "<<(cmd.h?"right":"left")<<" hand towards Robot "<<(rbt.h[cmd.h]+cmd.x)%n<<".\n";
rbt.h[cmd.h]=(rbt.h[cmd.h]+cmd.x)%n;
}else if(cmd.type==SWAP){
cout<<"Robot "<<rid<<" swaps a line of command with Robot "<<rbt.h[cmd.h]<<".\n";
swap(rbt.command[cmd.y],robot[rbt.h[cmd.h]].command[cmd.x]);
}else if(cmd.type==MIRROR){
cout<<"Robot "<<rid<<" modifies a line of command of Robot "<<rbt.h[cmd.h]<<".\n";
Mirror(robot[rbt.h[cmd.h]].command[cmd.x]);
}else if(cmd.type==REPLACE){
cout<<"Robot "<<rid<<" replaces a line of command of Robot "<<rbt.h[cmd.h]<<".\n";
robot[rbt.h[cmd.h]].command[cmd.x]=command[cmd.pointcmd];
}else if(cmd.type==ACTIVATE){
cout<<"Robot "<<rid<<" activates Robot "<<rbt.h[cmd.h]<<".\n";
doActivate(robot[rbt.h[cmd.h]],rbt.h[cmd.h]);
}
if(rbt.h[1]!=rid){
doTrigger(robot[rbt.h[1]],rbt.h[1],cmdcpy,fromTrigger);
}
}