[카카오 코드 / 예선] 카카오프렌즈 컬러링북
PS/etc.2018. 5. 4. 13:31
	
	[카카오 코드 / 예선] 카카오프렌즈 컬러링북 : https://programmers.co.kr/learn/courses/30/lessons/1829
<소스코드>
| 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <vector> using namespace std; int dr[] = {1, 0, -1, 0}; int dc[] = {0, 1, 0, -1}; int R, C; bool safe(int r, int c) {     return (0 <= r && r < R) && (0 <= c && c < C); } int dfs(vector<vector<int>> &picture, int r, int c, int val) {     int ret = 1;     picture[r][c] = 0;     for(int k=0; k<4; k++) {         int nr = r+dr[k];         int nc = c+dc[k];         if(safe(nr, nc) && picture[nr][nc]==val)             ret += dfs(picture, nr, nc, val);     }     return ret; } vector<int> solution(int m, int n, vector<vector<int>> picture) {     int number_of_area = 0;     int max_size_of_one_area = 0;     R = m; C = n;     for(int i=0; i<m; i++) {         for(int j=0; j<n; j++) {             if(picture[i][j] != 0) {                 int tmp = dfs(picture, i, j, picture[i][j]);                 number_of_area++;                 if(max_size_of_one_area < tmp)                     max_size_of_one_area = tmp;             }         }     }     vector<int> answer(2);     answer[0] = number_of_area;     answer[1] = max_size_of_one_area;     return answer; } | cs | 
'PS > etc.' 카테고리의 다른 글
| [POJ/1182] 먹이 사슬 (0) | 2018.07.25 | 
|---|---|
| [POJ/2431] Expedition (0) | 2018.06.27 | 
| <3-1> 나열하기 - 경우의 수 (0) | 2018.03.06 | 
