Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 플로이드
- queue
- 후쿠오카 요도바시 하카타
- DP
- 백준
- 후쿠오카
- 삼성 SW 테스트
- 후쿠오카 여행경비
- BFS
- 하카타역
- 완전탐색
- 플로이드 와샬
- 후쿠오카 4박 5일
- 너비 우선 탐색
- 삼성테스트
- 다이나믹 프로그래밍
- BOJ
- 일본 여행
- 시뮬레이션
- deque
- dfs
- 알고리즘
- 미로찾기
- 큐
- 완전 탐색
- IOS
- 후쿠오카 캐널시티
- 삼성시험
- 깊이 우선 탐색
- brute force
Archives
- Today
- Total
맛있는감귤
BOJ : 2573 빙산 본문
문제 : https://www.acmicpc.net/problem/2573
시간에 따라 맵이 바뀌는 문제이다.
얼음이 녹을 때 시간마다 -1인줄 알았는데 기준점에서 동서남북 상태에 따라 얼음 융해도가 다르다는 것을 간과한 것이 문제였다.
코드가 더럽게 되었는데 문제점이 있으면 댓글로 지적해주시면 감사하겠습니다.
#include <stdio.h> int R,C,cnt=0,time=0; int map[303][303]; bool isVisited[303][303]; int dr[4]={1,-1,0,0}; int dc[4]={0,0,1,-1}; void dfs(int r,int c){ isVisited[r][c] = true; for(int i=0;i<4;i++){ int nr = r+dr[i], nc = c+dc[i]; if(nr >= 0 && nc >= 0 && nr < R && nc < C && !isVisited[nr][nc] && map[nr][nc] > 0){ dfs(nr,nc); } } } int melt(int r,int c){ int num=0; for(int i=0;i<4;i++){ int nr = r+dr[i], nc = c+dc[i]; if(map[nr][nc] == 0){ ++num; } } return num; } int main(){ int n; scanf("%d%d",&R,&C); for(int i=0;i<R;i++){ for(int j=0;j<C;j++){ scanf("%d",&n); map[i][j] = n; } } while(true){ cnt=0; int meltMap[303][303]; // isVisited 배열 초기화 for(int i=0;i<R;i++){ for(int j=0;j<C;j++){ isVisited[i][j] = false; } } //빙하 개수 세기 for(int i=0;i<R;i++){ for(int j=0;j<C;j++){ if(!isVisited[i][j] && map[i][j] > 0){ cnt++; dfs(i,j); } } } //얼음 융해 for(int i=0;i<R;i++){ for(int j=0;j<C;j++){ if(map[i][j] == 0) continue; meltMap[i][j] = map[i][j] - melt(i, j); if(meltMap[i][j] < 0) meltMap[i][j] = 0; } } //얼음 크기 수정 for(int i=0;i<R;i++){ for(int j=0;j<C;j++){ map[i][j] = meltMap[i][j]; } } if(cnt >= 2) { printf("%d\n",time); break; } if(cnt == 0) { printf("0\n"); break; } time++; } }
'알고리즘 > 백준 알고리즘' 카테고리의 다른 글
BOJ : 1963 소수 경로 (0) | 2017.02.08 |
---|---|
BOJ : 5014 스타트링크 (0) | 2017.02.08 |
BOJ : 2468 안전 영역 (4) | 2017.02.04 |
BOJ : 12790 Mini Fantasy War (0) | 2017.02.03 |
BOJ : 2477 참외밭 (0) | 2017.01.19 |