| ์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
|---|---|---|---|---|---|---|
| 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 |
- ๋์
- ๋์์๋จ
- BFS
- ์๊ณ ๋ฆฌ์ฆ
- ๋ฐฑ์ค
- ์๋จ
- benefits
- lululemon
- usaco
- BOJ
- ์์ด
- silver
- ์ถ์ฒ
- ํ์ฟก
- ํ๋ฉ์ด๋
- ๐
- ์๋ฅ
- coding
- health
- Netflix
- ์ํ
- ๋ฆฌ๋ทฐ
- ์ฝ๋ฉ ํ ์คํธ
- ๊ฑด๊ฐ
- ํด์ค
- ์์ ํ์
- Algorithm
- ์นด์นด์ค
- 2020
- ๋ทํ๋ฆญ์ค
- Today
- Total
Lemonlover๐ง๐ปโ๏ธ
2020 ์นด์นด์ค ์ ์ ์ฌ์ ์ฝ๋ฉํ ์คํธ - ์๋ฌผ์ ์ ์ด์ ๋ณธ๋ฌธ
2020 ์นด์นด์ค ์ ์ ์ฌ์ ์ฝ๋ฉํ ์คํธ - ์๋ฌผ์ ์ ์ด์
Summer_lulu 2019. 12. 18. 00:06https://programmers.co.kr/learn/courses/30/lessons/60059
์ฝ๋ฉํ ์คํธ ์ฐ์ต - ์๋ฌผ์ ์ ์ด์ | ํ๋ก๊ทธ๋๋จธ์ค
[[0, 0, 0], [1, 0, 0], [0, 1, 1]] [[1, 1, 1], [1, 1, 0], [1, 0, 1]] true
programmers.co.kr
์ค๋์ 2020 ์นด์นด์ค ์ ์ ์ฌ์ ์ฝ๋ฉ ํ ์คํธ 3๋ฒ์งธ ๋ฌธ์ ์ ๋๋ค.
์ด ๋ฌธ์ ๋ ๋ฌด๋ ค ์ ๋ต๋ฅ 7%๋ฅผ ์๋ํ๋ ๋ฌธ์ ์ ๋๋ค.
์ค๊ณ๋ฅผ ์๊ฐํด๋ด๊ธฐ ์กฐ๊ธ ํ๋ค์๋ ์์ต๋๋ค. ๊ทธ๋ฅ ๋จธ๋ฆฟ์์ผ๋ก ์๋ฎฌ๋ ์ด์ ์ ๋๋ ค๋ณด๋ฉด
๊ฝค๋ ๊ฐ๋จํ๊ฒ ๋ณด์ด๋๋ฐ ์ค์ ๊ตฌํ์ ๋ค์ด๊ฐ๋ฉด ๋ํดํฉ๋๋ค.
์ด ๋ฌธ์ ์์ ๋ฐฐ์ธ ์ ์๋ ๊ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
1. ์ง๋๋ฅผ 90๋ ๋๋ ค์ ๊ธฐ์กด ์ฝ๋๋ฅผ ์ฌ์ฌ์ฉํ ์ ์๋ ๊ฒฝ์ฐ๊ฐ ์์์ ์ธ์งํ์.
2. ์ง๋๋ฅผ 90๋ ๋๋ฆฌ๋ ๋ฐฉ๋ฒ์ ํ์คํ ์์. (์ด๋ฟ๋ง ์๋๋ผ ์ ๋์นญ, ์ ๋์นญ ๋ ์ฐ์ตํด๋ณด์)
3. 2์ฐจ์ ๋ฐฐ์ด์ ๋ถ๋ถ์ ์ผ๋ก ์ ๊ทผํ๋ ๋ฐฉ๋ฒ์ ๋ํด์ ์๊ฐํด๋ณด์.
1. ์ง๋๋ฅผ 90๋ ๋๋ ค์ ๊ธฐ์กด ์ฝ๋ ์ฌ์ฌ์ฉํ ์ ์๋ ๊ฒฝ์ฐ
(์ถ์ฒ ๋ฌธ์ )
์ฌํ๊ฒ์ : https://www.acmicpc.net/problem/3085
๊ฒฝ์ฌ๋ก : https://www.acmicpc.net/problem/14890
'๊ฒฝ์ฌ๋ก' ๋ฌธ์ ๋ ์ผ์ฑ ๊ธฐ์ถ ๋ฌธ์ ๋ก ์ ๋ช ํ์ฃ . ์ด์ธ์๋ ์ ๊ฐ ๊ฒฝํํ๋ ์ฝ๋ฉํ ์คํธ์์๋ ๋งต์ 90๋ ๋๋ ค์
๊ธฐ์กด ์ฝ๋๋ฅผ ์ฌ์ฌ์ฉํ ์ ์๋ ๊ฒฝ์ฐ๋ฅผ ๋ง์ด ๋ง๋ฌ์ต๋๋ค.
๋ณดํต ์์ง๊ณผ ์ํ์ ๋ํ ๋ก์ง์ด ๋๊ฐ์ ๊ฒฝ์ฐ, ์ด ๋ฐฉ๋ฒ์ด ๋งค์ฐ ์ข์ต๋๋ค.
๊ธฐ์กด ์ฝ๋๋ฅผ ์ฌ์ฌ์ฉํจ์ผ๋ก์จ ๋๋ฒ๊น ์ด ์ฌ์์ง๊ณ , ์ฝ๋ฉ๋์ด ์ค์ด๋ค๊ฒ ๋ฉ๋๋ค.
2. n x n 2์ฐจ์ ๋ฐฐ์ด์ ๋ํ ์กฐ์ (90๋ ํ์ / ์ ๋์นญ / ์ ๋์นญ)
(์ถ์ฒ ๋ฌธ์ )
๋ง์ ์ฌ ์ด๋ฏผํ : https://www.acmicpc.net/problem/3023
์ ๋ฌธ์ ์์ ์ ๋์นญ, ์ ๋์นญ์ ๋ํด์ ๊ณต๋ถํ์ค ์ ์์ต๋๋ค.
๋์ด๋๋ ์ฝ์ง๋ง, ์ข์ ๋ฌธ์ ๋ผ๊ณ ์๊ฐํฉ๋๋ค.
(i, j) : i ํ, j ์ด ์ด๋ผ๊ณ ๊ฐ์ .
(1) 90๋ ์กฐ์
(i, j) => (j, n - i - 1)
(2) x์ถ ๋์นญ
(i, j) => (n - i - 1, j)
(3) y์ถ ๋์นญ
(i, j) => (i, n - j - 1)
(4) ์ ๋์นญ
(i, j) => (n - i - 1, n - j - 1)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
void turn(){
int tmp_arr[20][20]; // ์์๋ก ๋ฐฐ์ด์ ์์ฑํ์ฌ ์ด๊ณณ์ ์๋ณธ์ ์กฐ์ํ ๋ฐฐ์ด์ ๊ธฐ๋กํด
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++){
tmp_arr[n - i - 1][j] = arr[i][j]; // x์ถ ๋์นญ
tmp_arr[i][n - j - 1] = arr[i][j]; // y์ถ ๋์นญ
tmp_arr[n - i - 1][n - j - 1] = arr[i][j]; // ์ ๋์นญ
tmp_arr[j][n - i - 1] = arr[i][j]; // 90๋ ํ์
}
// ์๋ณธ ๋ฐฐ์ด์ ๋ค์ ๋ณต์ฌํ๋ ๊ณผ์
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
arr[i][j] = tmp_arr[i][j];
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
3. 2์ฐจ์ ๋ฐฐ์ด์ ๋ถ๋ถ์ ์ผ๋ก ์ ๊ทผ
์ด๋ฒ์๋ 2์ฐจ์ ๋ฐฐ์ด์ ๋ถ๋ถ์ ์ผ๋ก ์ ๊ทผํ๋ ๋ฐฉ๋ฒ์ ๋ํด์ ์์๋ณด๊ฒ ์ต๋๋ค.

์์ ๊ฐ์ด ์ค๋์ฟ ๊ฐ ์์ ๋, ํ๋ก๊ทธ๋๋ฐ์ ํตํด ๋ฌธ์ ๋ฅผ ํ๊ธฐ ์ํด์๋ ๋๊บผ์ด ์ ์ผ๋ก ๋๋ ์ ธ ์๋
3x3 ์์ญ์ ์ ๊ทผํ ํ์๊ฐ ์์ต๋๋ค.
์ด๊ฒ์ ๊ตฌํํ๊ธฐ ์ํด์๋ ์์์ ์ ์ก์์ฃผ๋ for๋ฌธ๊ณผ 3x3์ ์ ๊ทผํ๋ ์ด์ค for๋ฌธ์ด ํ์ํฉ๋๋ค.
์ฝ๋๋ก ๋ณด์์ฃ .
|
1
2
3
4
5
6
7
8
9
10
11
|
for(int i = 0; i < n / 3; i++){
for(int j = 0; j < n / 3; j++){
int sy = i * 3, sx = j * 3; // 3x3 ์ ์ฌ๊ฐํ ์ผ์ชฝ ๋งจ ์ ์ง์ ์์น๋ฅผ ๋จผ์ ์ก์์ค๋ค
for(int k = sy; k < sy + 3; k++){ // ์์ ์์น์์ ์ค๋ฅธ์ชฝ, ์๋์ชฝ์ผ๋ก ์ต๋ +3๋งํผ ์ ํ์ ๋๋ค
for(int l = sx; l < sx + 3; l++){
cout << mp[k][l];
}
cout << endl;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
์ ์ฝ๋์์ n = 9 ์ ๋๋ค.
|
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
|
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int n, m;
void turn_90(vector<vector<int>> &arr){
int ret[21][21] = {};
for(int i = 0; i < m; i++)
for(int j = 0; j < m; j++)
ret[j][m - i - 1] = arr[i][j];
for(int i = 0; i < m; i++)
for(int j = 0; j < m; j++)
arr[i][j] = ret[i][j];
}
bool solution(vector<vector<int>> k, vector<vector<int>> l) {
m = k.size(), n = l.size();
bool result = true;
for(int dir = 0; dir < 4; dir++){
for(int off_y = n - 1; off_y >= -n + 1; off_y--){
for(int off_x = n - 1; off_x >= -n + 1; off_x--){
result = true;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
int ny = i + off_y, nx = j + off_x;
if(ny < 0 || ny >= m || nx < 0 || nx >= m) {
if(l[i][j] == 0) result = false;
}
else {
if((l[i][j] == 0 && k[ny][nx] == 0) || (l[i][j] == 1 && k[ny][nx] == 1)) result = false;
}
}
}
if(result) return true;
}
}
turn_90(k);
}
return false;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'์ฝ๋ฉ ํ ์คํธ ๋๋น ์ถ์ฒ ๋ฌธ์ ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| 2020 ์นด์นด์ค ์ ์ ์ฌ์ ์ฝ๋ฉํ ์คํธ - ๋ธ๋ก ์ด๋ํ๊ธฐ (1) | 2019.12.20 |
|---|---|
| 2020 ์นด์นด์ค ์ ์ ์ฌ์ ์ฝ๋ฉํ ์คํธ - ๊ฐ์ฌ ๊ฒ์ (0) | 2019.12.19 |
| 2020 ์นด์นด์ค ์ ์ ์ฌ์ ์ฝ๋ฉํ ์คํธ - ๊ดํธ ๋ณํ (0) | 2019.12.17 |
| 2020 ์นด์นด์ค ์ ์ ์ฌ์ ์ฝ๋ฉํ ์คํธ - ๋ฌธ์์ด ์์ถ (0) | 2019.12.16 |
| BOJ - ๋ก๋ด ์ฒญ์๊ธฐ (4991) (1) | 2019.12.12 |