회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
어디가 틀린지 알고싶습니다..
2174번 - 로봇 시뮬레이션
apdh25
4년 전
0
반례라던지... 코드상에 문제라던지... 피드백 주시면 감사드리게습니다... 도와주세요
#include <iostream> #include <vector> #include <string> #include <cstring> #include <stack> #include <queue> #include <map> #include <algorithm> using namespace std; struct Robot { int number; int idx1; int idx2; char dir; Robot(int number, int idx1, int idx2, char dir) { this->number = number; this->idx1 = idx1; this->idx2 = idx2; this->dir = dir; } Robot() {} }; struct Order { int n; char type; int cnt; Order() {} Order(int n, char type, int cnt) { this->n = n; this->type = type; this->cnt = cnt; } }; Robot arr[101][101]; Robot robots[101]; vector<Order>order; int A, B; int N, M; void init() { cin >> A >> B; cin >> N >> M; for (int i = 0, cnt = 1; i < N; i++, cnt++) { int x, y; char dir; cin >> x >> y >> dir; robots[cnt] = Robot(cnt, B - y, x - 1, dir); arr[B - y][x - 1] = Robot(cnt, B - y, x - 1, dir); } for (int i = 0; i < M; i++) { int n; char type; int cnt; cin >> n >> type >> cnt; order.push_back(Order(n, type, cnt)); } } void rotate_left(int n) { switch (robots[n].dir) { case 'W': robots[n].dir = 'S'; arr[robots[n].idx1][robots[n].idx2].dir = 'S'; break; case 'E': robots[n].dir = 'N'; arr[robots[n].idx1][robots[n].idx2].dir = 'N'; break; case 'N': robots[n].dir = 'W'; arr[robots[n].idx1][robots[n].idx2].dir = 'W'; break; case 'S': robots[n].dir = 'E'; arr[robots[n].idx1][robots[n].idx2].dir = 'E'; break; } } void rotate_right(int n) { switch (robots[n].dir) { case 'W': robots[n].dir = 'N'; arr[robots[n].idx1][robots[n].idx2].dir = 'N'; break; case 'E': robots[n].dir = 'S'; arr[robots[n].idx1][robots[n].idx2].dir = 'S'; break; case 'N': robots[n].dir = 'E'; arr[robots[n].idx1][robots[n].idx2].dir = 'E'; break; case 'S': robots[n].dir = 'W'; arr[robots[n].idx1][robots[n].idx2].dir = 'W'; break; } } bool move_toward(int n) { int idx1 = robots[n].idx1; int idx2 = robots[n].idx2; switch (robots[n].dir) { case 'W': { if (idx2 - 1 < 0) { printf("Robot %d crashes into the wall\n", n); return true; } else if (arr[idx1][idx2 - 1].number != 0) { printf("Robot X crashes into robot Y\n", n, arr[idx1][idx2 - 1].number); return true; } robots[n] = Robot(n, idx1, idx2 - 1, robots[n].dir); arr[idx1][idx2 - 1] = robots[n]; arr[idx1][idx2] = Robot(0, 0, 0, 0); break; } case 'E': { if (idx2 + 1 >= A) { printf("Robot %d crashes into the wall\n", n); return true; } else if (arr[idx1][idx2 + 1].number != 0) { printf("Robot X crashes into robot Y\n", n, arr[idx1][idx2 + 1].number); return true; } robots[n] = Robot(n, idx1, idx2 + 1, robots[n].dir); arr[idx1][idx2 + 1] = robots[n]; arr[idx1][idx2] = Robot(0, 0, 0, 0); break; } case 'N': { if (idx1 - 1 < 0) { printf("Robot %d crashes into the wall\n", n); return true; } else if (arr[idx1 - 1][idx2].number != 0) { printf("Robot X crashes into robot Y\n", n, arr[idx1 - 1][idx2].number); return true; } robots[n] = Robot(n, idx1 - 1, idx2, robots[n].dir); arr[idx1 - 1][idx2] = robots[n]; arr[idx1][idx2] = Robot(0, 0, 0, 0); break; } case 'S': { if (idx1 + 1 >= B) { printf("Robot %d crashes into the wall\n", n); return true; } else if (arr[idx1 + 1][idx2].number != 0) { printf("Robot X crashes into robot Y\n", n, arr[idx1 + 1][idx2].number); return true; } robots[n] = Robot(n, idx1 + 1, idx2, robots[n].dir); arr[idx1 + 1][idx2] = robots[n]; arr[idx1][idx2] = Robot(0, 0, 0, 0); break; } } return false; } bool simulate(int n, char type, int cnt) { switch (type) { case 'L': { for (int i = 0; i < cnt; i++) { //왼쪽회전 rotate_left(n); } } break; case 'R': { for (int i = 0; i < cnt; i++) { //오른쪽회전 rotate_right(n); } } break; default: { for (int i = 0; i < cnt; i++) { //전진 if (move_toward(n)) return true; } } } return false; } void solve() { for (auto elem : order) { if (simulate(elem.n, elem.type, elem.cnt)) return; } cout << "OK" << endl; } int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); init(); solve(); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
apdh25 4년 전
반례라던지... 코드상에 문제라던지... 피드백 주시면 감사드리게습니다... 도와주세요