-
[C++] ์ผ์ฑ 4014. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ํ์ฃผ๋ก ๊ฑด์ค์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:16728x90
(1์๊ฐ 30๋ถ) ์๊ฐ๋๋๋๋ก ์ฝ๋ฉํ๋ฉด์ ์์ธ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ๋ ์๊ฐ์ด ์ค๋๊ฑธ๋ฆฐ๋๋..
#include<iostream> #include<vector> #include<string.h> using namespace std; int arr[20][20]; bool bridge[20][20]; int N, X; int main() { int T; cin >> T; for (int t = 1; t <= T; t++) { memset(arr, 0, sizeof(arr)); memset(bridge, false, sizeof(bridge)); cin >> N >> X; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> arr[i][j]; } } int count = 0; for (int i = 0; i < N; i++) { int j = 0; int value = arr[i][j++]; while (j < N) { if (arr[i][j] < value) { if (j + X - 1 >= N) { break; } bool check = true; for (int k = 0; k < X; k++) { if (arr[i][j + k] != value - 1 || bridge[i][j + k] == true) { check = false; } bridge[i][j + k] = true; } if (check) { j = j + X - 1; value = value - 1; } else break; } else if (arr[i][j] > value) { if (j - X < 0) { break; } bool check = true; for (int k = 1; k <= X; k++) { if (arr[i][j - k] != arr[i][j] - 1 || bridge[i][j - k] == true) { check = false; } bridge[i][j - k] = true; } if (check) { value = arr[i][j]; } else break; } j++; } if (j == N) { //cout << i << "ํ ํด๋ฆฌ์ด" << endl; count++; } } memset(bridge, false, sizeof(bridge)); for (int j = 0; j < N; j++) { int i = 0; int value = arr[i++][j]; while (i < N) { if (arr[i][j] < value) { if (i + X - 1 >= N) { break; } bool check = true; for (int k = 0; k < X; k++) { if (arr[i + k][j] != value - 1 || bridge[i + k][j] == true) { check = false; } bridge[i+k][j] = true; } if (check) { i = i + X - 1; value = value - 1; } else break; } else if (arr[i][j] > value) { if (i - X < 0) { break; } bool check = true; for (int k = 1; k <= X; k++) { if (arr[i - k][j] != arr[i][j] - 1 || bridge[i - k][j] == true) { check = false; } bridge[i - k][j] == true; } if (check) { value = arr[i][j]; } else break; } i++; } if (i == N) { count++; //cout << j << "์ด ํด๋ฆฌ์ด" << endl; } } cout << "#" << t << " " << count << endl; } }
728x90'์ฝ๋ฉํ ์คํธ > ์ฝ๋ฉํ ์คํธ ์ฐ์ต' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++] ์ผ์ฑ 2477. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์ฐจ๋ ์ ๋น์ (0) 2020.10.27 [C++] ๋ฐฑ์ค 1389๋ฒ. ์ผ๋น ๋ฒ ์ด์ปจ์ 6๋จ๊ณ ๋ฒ์น (0) 2020.10.27 [C++] ๋ฐฑ์ค 9372๋ฒ. ์๊ทผ์ด์ ์ฌํ (0) 2020.10.27 [C++] ์ผ์ฑ 1952. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์์์ฅ (0) 2020.10.27 [C++] ์ผ์ฑ 2382. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ๋ฏธ์๋ฌผ ๊ฒฉ๋ฆฌ (0) 2020.10.27