https://www.acmicpc.net/problem/2174
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 105;
int a, b;
int n, m;
struct INFO { int x, y; char dir; };
vector<INFO> robot;
int ans = -1;
int main(void) {
cin >> a >> b;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int ii, jj;
char dir;
cin >> ii >> jj >> dir;
robot.push_back({ ii,jj,dir });
}
for (int cmd = 0; cmd < m; cmd++) {
int num, count;
char c;
cin >> num >> c >> count;
int flag = 0; //0:정상, 1:벽충돌, 2:로봇충돌
int movei = robot[num - 1].x;
int movej = robot[num - 1].y;
char dir = robot[num - 1].dir;
for (int kk = 0; kk < count; kk++) {
if (c == 'L') {
if (dir == 'N') dir = 'W';
else if (dir == 'W') dir = 'S';
else if (dir == 'S') dir = 'E';
else if (dir == 'E') dir = 'N';
robot[num - 1].dir = dir;
}
else if (c == 'R') {
if (dir == 'N') dir = 'E';
else if (dir == 'W') dir = 'N';
else if (dir == 'S') dir = 'W';
else if (dir == 'E') dir = 'S';
robot[num - 1].dir = dir;
}
else if (c == 'F') {
if (dir == 'N') {
robot[num - 1].y += 1;
}
else if (dir == 'W') {
robot[num - 1].x -= 1;
}
else if (dir == 'S') {
robot[num - 1].y -= 1;
}
else if (dir == 'E') {
robot[num - 1].x += 1;
}
if (!(robot[num - 1].x >= 1 && robot[num - 1].x <= a && robot[num - 1].y >= 1 && robot[num - 1].y <= b)) {
flag = 1;
}
for (int kk = 0; kk < robot.size(); kk++) {
if (kk == num - 1) continue;
if (robot[kk].x == robot[num - 1].x && robot[kk].y == robot[num - 1].y) {
flag = 2;
ans = kk;
break;
}
}
}
if (flag != 0) {
if (flag == 1) cout << "Robot " << num <<" crashes into the wall" << endl;
else if (flag == 2) cout << "Robot " << num << " crashes into robot "<< ans+1 << endl;
return 0;
}
}
}
cout << "OK" << endl;
}
'백준 알고리즘 > 구현' 카테고리의 다른 글
활주로 건설 C++ (0) | 2022.04.23 |
---|---|
줄기세포 배양 C++ (0) | 2022.04.23 |
스위치 켜고 끄기 (0) | 2022.03.08 |
치즈 C++ (0) | 2022.03.07 |
마법사 상어와 토네이도 C++ (0) | 2022.02.15 |