회원가입
로그인
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
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
13460문제 반례 여러가지 찾아서 돌려봤는데 틀립니다.
13460번 - 구슬 탈출 2
shincchh
5년 전
0
반례 하나만 들어주세요 ㅠㅠㅠ
도저히 못찾겠어요..
#include <stdio.h> #include <queue> using namespace std; #define SIZE 15 struct DAT { int dir; int dx; int dy; int count; }; int dx[4] = { -1, 1, 0, 0 }; int dy[4] = { 0, 0, -1, 1 }; queue<DAT> qR; queue<DAT> qB; char map[SIZE][SIZE]; int gdx, gdy; int width, height; int Bfs() { int result = 0; int queueCount = -1; while (true) { if(qR.size() == 0) return -1; int dxR = qR.front().dx; int dyR = qR.front().dy; int cR = qR.front().count; int dR = qR.front().dir; int dxB = qB.front().dx; int dyB = qB.front().dy; int cB = qB.front().count; int dB = qB.front().dir; queueCount = (cR < cB) ? cR : cB; bool qCheckR = false; bool qCheckB = false; if (queueCount == cR) { qCheckR = true; qR.pop(); //printf("%d pop %d %d\n", queueCount, dxR, dyR); } if (queueCount == cB) { qCheckB = true; qB.pop(); //printf(" %d pop %d %d\n", queueCount, dxB, dyB); } for (int i = 0; i < 4; i++) { int tempXR = dx[i]; int tempYR = dy[i]; int tempXB = dx[i]; int tempYB = dy[i]; bool blueCheck = false; int countR = 0; int countB = 0; bool nextR = false; bool nextB = false; bool oneMore = false; while (nextR == false || nextB == false || oneMore == false) { if (nextR == true && nextB == true) oneMore = true; if ((qCheckR == true && map[dyR + tempYR][dxR + tempXR] == '.') && ((dxB + tempXB != dxR + tempXR + dx[i]) || (dyB + tempYB != dyR + tempYR + dy[i]))) { countR++; tempXR += dx[i]; tempYR += dy[i]; } else nextR = true; if ((qCheckB == true && map[dyB + tempYB][dxB + tempXB] == '.') && ((dxB + tempXB + dx[i] != dxR + tempXR) || (dyB + tempYB + dy[i] != dyR + tempYR))) { countB++; tempXB += dx[i]; tempYB += dy[i]; } else nextB = true; } if (qCheckB == false) {} else if (map[dyB + tempYB][dxB + tempXB] == 'O') { blueCheck = true; } else { if ((countB != 0 || countR != 0)) { if (map[dyB + tempYB + +dy[i]][dxB + tempXB + +dx[i]] == 'O') continue; qB.push({ i, dxB + tempXB - dx[i], dyB + tempYB - dy[i], cB + 1 }); //printf(" push %d %d\n", dxB + tempXB - dx[i], dyB + tempYB - dy[i]); } } if (qCheckR == false) {} if (map[dyR + tempYR][dxR + tempXR] == 'O') { if (map[dyB + tempYB + +dy[i]][dxB + tempXB + +dx[i]] == 'O') continue; result = cR + 1; return result; } else { if (blueCheck == true) continue; if ((countB != 0 || countR != 0)) { qR.push({i, dxR + tempXR - dx[i], dyR + tempYR - dy[i], cR + 1 }); //printf(" push %d %d\n", dxR + tempXR - dx[i], dyR + tempYR - dy[i]); } } if (queueCount >= 10) return -1; } } return -1; }; void Input() { scanf_s("%d %d ", &height, &width); for (int i = 0; i < height; i++) { for (int j = 0; j < width + 1; j++) { scanf_s("%c", &map[i][j]); if (map[i][j] == 'O') { gdx = i; gdy = j; } else if(map[i][j] == 'R') { qR.push({ -1, j, i, 0}); map[i][j] = '.'; } else if (map[i][j] == 'B') { qB.push({ -1, j, i, 0 }); map[i][j] = '.'; } } } }; int main() { int result = 0; Input(); result = Bfs(); printf("%d", result); }
댓글을 작성하려면
로그인
해야 합니다.
shincchh 5년 전
반례 하나만 들어주세요 ㅠㅠㅠ
도저히 못찾겠어요..