반응형
https://www.acmicpc.net/problem/2174
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string.h>
#include <cstring>
using namespace std;
int A, B, N, M;
int map[110][110];
int arr[3][110];
int order[3][110];
char dir;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,-1,0,1 };
int flag;
void doOrder(int d, int turn) {
int x = arr[0][d];
int y = arr[1][d];
int ddir = arr[2][d];
int num = order[2][turn];
if (order[1][turn] == 0) {
ddir = arr[2][d] = (ddir + (3 * num)) % 4;
}
else if (order[1][turn] == 1) {
//ddir = arr[2][d] = (ddir + (3 * num)) % 4;
ddir = arr[2][d] = (ddir + (1 * num)) % 4;
}
else if (order[1][turn] == 2) {
map[B + 1 - y][x] = 0;
for (int a = 0; a < num; a++) {
x = arr[0][d] = x + dx[ddir];
y = arr[1][d] = y + dy[ddir];
if (map[B + 1 - y][x] != 0) {
printf("Robot %d crashes into robot %d", d, map[B+1 - y][x]);
flag = 1;
break;
}
if (arr[0][d] <= 0 || arr[1][d] <= 0 || arr[0][d] > A || arr[1][d] > B) {
printf("Robot %d crashes into the wall", d);
flag = 1;
break;
}
}
map[B + 1 - y][x] = d;
}
}
void solve() {
for (int i = 1; i <= M; i++) {
doOrder(order[0][i], i);
if (flag == 1) break;
}
}
int main() {
scanf("%d%d", &A, &B);
scanf("%d%d", &N, &M);
flag = 0;
int cnt = 1;
for (int i = 1; i <= N; i++) {
scanf("%d", &arr[0][i]);
scanf("%d", &arr[1][i]);
map[B + 1 - arr[1][i]][arr[0][i]] = cnt;
cnt++;
scanf("%s", &dir);
if (dir == 'E') arr[2][i] = 0;
if (dir == 'S') arr[2][i] = 1;
if (dir == 'W') arr[2][i] = 2;
if (dir == 'N') arr[2][i] = 3;
}
for (int j = 1; j <= M; j++) {
scanf("%d", &order[0][j]);
scanf("%s", &dir);
if (dir == 'L') order[1][j] = 0;
if (dir == 'R') order[1][j] = 1;
if (dir == 'F') order[1][j] = 2;
scanf("%d", &order[2][j]);
}
flag = 0;
solve();
if (flag == 0) {
printf("OK");
}
}
반응형