QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#508269 | #7965. 机器人 | vorDeal | TL | 0ms | 0kb | C++20 | 3.5kb | 2024-08-07 12:02:09 | 2024-08-07 12:02:09 |
answer
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
struct
{
int hand[2];
string command[11];
} robot[100];
string mirror(string s);
void trigger(int id, string con);
void execute(int id, string pro);
void activate(int id);
int main()
{
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
{
cin >> robot[i].hand[0] >> robot[i].hand[1];
for (int j = 0; j <= m; j++)
getline(cin, robot[i].command[j]);
}
for (int id = 0; k > 0; id++)
activate(id % n);
return 0;
}
string mirror(string s)
{
if (s == "SLACKOFF")
return s;
if (s.substr(0, 7) == "TRIGGER")
{
int pos = s.find(':') + 2;
s.replace(pos, s.length() - pos, mirror(s.substr(pos, s.length() - pos)));
return s;
}
int pos = s.find(' ') + 1;
s[pos] = (s[pos] == '0' ? '1' : '0');
return s;
}
void trigger(int id, string con)
{
for (int i = 1; i <= m; i++)
if (robot[id].command[i].substr(0, 7) == "TRIGGER" &&
con == robot[id].command[i].substr(8, robot[id].command[i].find(':') - 8))
{
execute(id, robot[id].command[i]);
break;
}
return;
}
void execute(int id, string pro)
{
if (k == 0)
return;
if (pro == "SLACKOFF")
printf("Robot %d slacks off.\n", id), k--;
else if (pro.substr(0, 4) == "MOVE")
{
int h = pro[5] - '0';
int z = atoi(pro.substr(7, pro.length() - 7).c_str());
robot[id].hand[h] += z, robot[id].hand[h] %= n;
printf("Robot %d moves its %s hand towards Robot %d.\n", id, (h == 0 ? "left" : "right"), robot[id].hand[h]);
k--;
}
else if (pro.substr(0, 4) == "SWAP")
{
int h = pro[5] - '0';
int x = atoi(pro.substr(7, pro.find(' ', 7) - 7).c_str());
int y = atoi(pro.substr(pro.find(' ', 7) + 1, pro.length() - pro.find(' ', 7) - 1).c_str());
swap(robot[id].command[y], robot[robot[id].hand[h]].command[x]);
printf("Robot %d swaps a line of command with Robot %d.\n", id, robot[id].hand[h]);
k--;
}
else if (pro.substr(0, 6) == "MIRROR")
{
int h = pro[7] - '0';
int x = atoi(pro.substr(9, pro.length() - 9).c_str());
robot[robot[id].hand[h]].command[x] = mirror(robot[robot[id].hand[h]].command[x]);
printf("Robot %d modifies a line of command of Robot %d.\n", id, robot[id].hand[h]);
k--;
}
else if (pro.substr(0, 7) == "REPLACE")
{
int h = pro[8] - '0';
int x = atoi(pro.substr(10, pro.find(' ', 10) - 10).c_str());
robot[robot[id].hand[h]].command[x] = pro.substr(pro.find(' ', 10) + 1, pro.length() - pro.find(' ', 10) - 1);
printf("Robot %d replaces a line of command of Robot %d.\n", id, robot[id].hand[h]);
k--;
}
else if (pro.substr(0, 8) == "ACTIVATE")
{
int h = pro[9] - '0';
printf("Robot %d activates Robot %d.\n", id, robot[id].hand[h]);
k--, activate(robot[id].hand[h]);
}
else if (pro.substr(0, 7) == "TRIGGER")
execute(id, pro.substr(pro.find(':') + 2, pro.length() - pro.find(':') - 2));
if (robot[id].hand[1] != id)
trigger(robot[id].hand[1], pro.substr(0, pro.find(' ')));
return;
}
void activate(int id)
{
for (int i = 1; i <= m; i++)
if (robot[id].command[i].substr(0, 7) != "TRIGGER")
execute(id, robot[id].command[i]);
return;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
100 1 300000 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 1 1 REPLACE 0 1 REPLACE 1 1 REPLACE 1 1 REPLACE 1 1 REPLACE 1 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE...
output:
Robot 0 replaces a line of command of Robot 1. Robot 1 replaces a line of command of Robot 2. Robot 2 replaces a line of command of Robot 3. Robot 3 replaces a line of command of Robot 4. Robot 4 replaces a line of command of Robot 5. Robot 5 replaces a line of command of Robot 6. Robot 6 replaces a...