회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
으어...반례 찾아주시면 감사하겠습니다 ㅠㅠ
14503번 - 로봇 청소기
sujae03
6년 전
0
맞다고 생각하는데 왜 자꾸 틀렸다고 나오는 걸까요 ㅠㅠ
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int map[51][51]; int visit[51][51]; int dir_x[4] = { -1,0,1,0 }; int dir_y[4] = { 0,-1,0,1 }; int N, M; // x,y int r, c, d; int cnt = 1; int chk = 0; short dirr; void Input() { scanf("%d%d", &N, &M); getchar(); scanf("%d%d%d", &r, &c, &d); getchar(); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { scanf("%d", &map[i][j]); if (map[i][j] == 1) { visit[i][j] = 1; } } getchar(); } if (map[r][c] == 0) { //cnt++; } } int DIR_X(short direction) { // 북쪽 if (direction == 0) { return 0; } // 동쪽 else if (direction == 1) { return 1; } // 남쪽 else if (direction == 2) { return 0; } //북쪽 else if (direction == 3) { return -1; } } int DIR_Y(short direction) { // 북쪽 if (direction == 0) { return -1; } // 동쪽 else if (direction == 1) { return 0; } // 남쪽 else if (direction == 2) { return 1; } //서쪽 else if (direction == 3) { return 0; } } void Change_Direction(short direction) { // 북쪽 if (direction == 0) { dirr = 1; } // 동쪽 else if (direction == 1) { dirr = 2; } // 남쪽 else if (direction == 2) { dirr = 3; } //서쪽 else if (direction == 3) { dirr = 0; } } int Back_X(short direction) { // 북쪽 if (direction == 0) { return 1; } // 동쪽 else if (direction == 1) { return 0; } // 남쪽 else if (direction == 2) { return -1; } //서쪽 else if (direction == 3) { return 0; } } int Back_Y(short direction) { // 북쪽 if (direction == 0) { return 0; } // 동쪽 else if (direction == 1) { return 1; } // 남쪽 else if (direction == 2) { return 0; } //서쪽 else if (direction == 3) { return -1; } } void U_Test() { for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { printf("%d ", visit[i][j]); } printf("\n"); } printf("\n"); } void dfs(int x, int y) { if (chk) { return; } if (!visit[x][y]) { visit[x][y] = cnt; } //U_Test(); for (int i = 0; i < 4; i++) { //printf(" Before => x: %d y : %d dir: %d\n", x, y,dirr); int d_x = DIR_X(dirr); int d_y = DIR_Y(dirr); Change_Direction(dirr); //printf(" After => x: %d y : %d dir: %d\n", x+d_x, y+d_y, dirr); //printf("\n"); if (x + d_x < 0 || x + d_x >= N || y + d_y < 0 || y + d_y >= N) {} if (!visit[x + d_x][y + d_y] && map[x + d_x][y + d_y] == 0) { int pos_x = x + d_x; int pos_y = y + d_y; cnt++; dfs(pos_x, pos_y); if (chk) { return; } } } // Back이 벽이라면 if (map[x + Back_X(dirr)][y + Back_Y(dirr)] == 1) { chk = 1; return; } else { //printf("Back => x : %d, y: %d , dir : %d", x + Back_X(dirr), y + Back_Y(dirr),dirr); dfs(x + Back_X(dirr), y + Back_Y(dirr)); } } int main(void) { freopen("in.txt", "r", stdin); // 입력 Input(); //dfs dirr = d; dfs(r, c); printf("%d\n", cnt); return 0; }
jwvg0425
6년 전
1
문제 번호를 적어주셔야 할 것 같습니다 ㅎㅎ
댓글을 작성하려면
로그인
해야 합니다.
sujae03 6년 전
맞다고 생각하는데 왜 자꾸 틀렸다고 나오는 걸까요 ㅠㅠ