회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
반례를 못찾겠습니다
13460번 - 구슬 탈출 2
njh7799
5년 전
0
블로그에 있던 100가지 케이스를 시도해 보았는데도 찾지 못했습니다ㅠ 혹시 도와주실 수 있으신가요?
#include<cstdio> #include<queue> using namespace std; struct Point { int x; int y; bool operator== (Point &rhs) { return this->x == rhs.x && this->y == rhs.y; } bool operator!= (Point &rhs) { return !(this->x == rhs.x && this->y == rhs.y); } }; struct RB { Point R; Point B; }; int n, m; char a[10][10]; int dx[4] = { -1, 0, 1, 0 }; int dy[4] = { 0, 1, 0, -1}; Point R, B, O; int d[10] = { 0, }; // 매 시행마다 구슬을 굴리는 함수 //P가 처리할 구슬 P2가 다른 구슬, O가 탈출 점 Point roll(Point P, Point P2, Point O, int dir) { while (1) { Point next = { P.x + dx[dir], P.y + dy[dir] }; if (P == O) break; if (next == P2 && next != O) break; if (a[next.x][next.y] == '#') break; P = next; } return P; } int main() { // freopen("input.txt", "r", stdin); scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", a[i]); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == 'R') R = { i,j }, a[i][j]='.'; else if (a[i][j] == 'B') B = { i,j }, a[i][j] = '.'; else if (a[i][j] == 'O') O = { i,j }, a[i][j] = '.'; } } queue<RB> q; q.push({ R, B }); int ans = 11; //시간 t가 증가함에 따라 진행되도록 설정했습니다. for (int t = 0; t<ans; t++) { queue<RB> q2; while (!q.empty()) { RB crr = q.front(); q.pop(); if (crr.B == O) continue;// B가 O에 빠지는 경우는 실패이기 때문에 continue else if (crr.R == O) {// B가 안빠지고 R이 빠지는 경우 성공 ans = t; break; } // for (int dir = 0; dir < 4; dir++) { // 구슬을 굴려줍니다. R 구슬과 B 구슬이 서로의 경로를 막으면 안되기 때문데 R, B, R 세번의 처리를 진행했습니다. Point tempR = roll(crr.R, crr.B, O, dir); Point tempB = roll(crr.B, tempR, O, dir); tempR = roll(tempR, tempB, O, dir); // if (crr.R == tempR && crr.B == tempB) continue; q2.push({ tempR, tempB }); } } q = q2; } ans = ans == 11 ? -1 : ans; printf("%d", ans); // fclose(stdout); }
댓글을 작성하려면
로그인
해야 합니다.
njh7799 5년 전
블로그에 있던 100가지 케이스를 시도해 보았는데도 찾지 못했습니다ㅠ 혹시 도와주실 수 있으신가요?