반응형
// c++ 쓰기 #include#include using namespace std; int n; // 행 열 갯수 int arr_origin[101][101] = { 0, }; int arr[101][101] = { 0, }; int rain[101] = { 0, }; // 비의 양 오면 1 int rain_cnt = 0; int limit = 6; int result = 0; int biggist_result = 0; int x_offset[4] = {0,0,-1,1}; // 상 하 좌 우 int y_offset[4] = {1,-1,0,0}; void func(int x, int y); int main(void) { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int temp; cin >> temp; arr_origin[i][j] = temp; if (rain[temp]==0) { rain[temp] = 1; rain_cnt++; } } } int idx = 0; for (int k = 0; k < rain_cnt; k++) { // rain cnt // 초기화 memcpy(arr, arr_origin, sizeof(arr)); result = 0; while (rain[idx]==0) { idx++; } limit = idx; idx++; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (arr[i][j]>limit) { func(i, j); result++; } } } if (biggist_result =n || _y<0 || _y>=n || arr[_x][_y]<=limit) { continue; } func(_x, _y); } return; } void func(int x,int y) { arr[x][y] = -1; // 방문했음 for (int i = 0; i < 4; i++) { int _x = x + x_offset[i]; int _y = y + y_offset[i]; if (_x<0 || _x>=n || _y<0 || _y>=n || arr[_x][_y]<=limit) { continue; } func(_x, _y); } return; }
반응형