#include <bits/stdc++.h>
using namespace std;
#define oi op[id]
inline int read();
const int N = 10000;
int n , m, k;
int sum ;
struct oper {
string n ;
int h , x , y;
string cmb;
int cmd;
}op[N];
int t;
struct bob {
int h[4];
int o[N];
}a[N];
void reand(int id) {
cin >> oi.n;
if(oi.n == "SLACKOFF") return ;
else if(oi.n == "MOVE") {
cin >> oi.h >> oi.x;
}
else if(oi.n == "SWAP") {
cin >> oi.h >> oi.x >> oi.y;
}
else if(oi.n == "MIRROR") {
cin >> oi.h >> oi.x;
}
else if(oi.n == "REPLACE") {
cin >> oi.h >> oi.x;
oi.cmd = ++t;
reand(t);
}
else if(oi.n == "ACTIVATE") {
cin >> oi.h;
}
else if(oi.n == "TRIGGER") {
cin >> oi.cmb;
oi.cmb.pop_back();
oi.cmd = ++t;
reand(t);
}
return ;
}
#undef oi
#define ot op[tmp]
#define otri op[a[t].o[i]]
void work(int id, int robert, int l_robert) {
oper oi = op[id];
if(oi.n == "SLACKOFF") {
cout << "Robot " << robert << " slacks off.\n";
sum++;
if(sum >= k)return;
}
else if(oi.n == "MOVE") {
int to = (to + oi.x) % n;
cout << "Robot " << robert << " moves its " << (oi.h == 0 ? "left" : "right") << " hand towards Robot " << a[robert].h[oi.h] << ".\n";
sum ++;
if(sum >= k)return;
}
else if(oi.n == "SWAP") {
swap(a[robert].o[oi.y] , a[a[robert].h[oi.h]].o[oi.x]);
cout << "Robot " << robert << " swaps a line of command with Robot " << a[robert].h[oi.h] << ".\n";
sum ++;
if(sum >= k)return;
}
else if(oi.n == "MIRROR") {
int tmp = a[a[robert].h[oi.h]].o[oi.x];
cout << "Robot "<< robert << " modifies a line of command of Robot " << a[robert].h[oi.h] << ".\n";
if(oi.n == "TRIGGER") {
int t = op[tmp].cmd;
op[t].h ^= 1;
}
else ot.h ^= 1;
sum++;if(sum >= k)
return;
}
else if(oi.n == "REPLACE") {
cout << "Robot "<< robert << " replaces a line of command of Robot " << a[robert].h[oi.h] << ".\n";
sum ++;if(sum >= k)return;
a[a[robert].h[oi.h]].o[oi.x]=oi.cmd;
}
else if(oi.n == "ACTIVATE") {
cout<<"Robot " << robert << " activates Robot " << a[robert].h[oi.h] <<".\n";
sum ++;
if(sum >= k)
return;
for(int i = 1 ; i <= m and sum < k;i ++)
work(a[a[robert].h[oi.h]].o[i],a[robert].h[oi.h],0);
if(sum >= k)
return;
}
else if(oi.n == "TRIGGER") {
return;
}
int t = a[robert].h[1];
if(t == robert) return;
for(int i = 1 ; i <= m and sum < k;i++)
if(otri.n == "TRIGGER"){
bool flag=0;
if(otri.cmb != "TRIGGER" and otri.cmb == oi.n)
work(otri.cmd,t,1),flag = 1;
else if(otri.cmb == "TRIGGER" && l_robert)
work(otri.cmd,t,1),flag = 1;
if(flag) break;
}
return;
}
main() {
cin >> n >> m >> k;
for(int i = 0; i < n; i++) {
cin >> a[i].h[0] >> a[i].h[1];
for(int j = 1; j <= m; j++) {
a[i].o[j] = ++t;
reand(t);
}
}
int now = 0;
while(sum < k) {
for(int i = 1; i <= m and sum < k; i++) {
work(a[now].o[i], now, 0);
}
if(sum >= k) return 0;
now = (now + 1) % n;
}
return 0;
}
样例只过了#2 和 #3。
关注 ×3