*BOJ의 드래곤커브와 비슷한 규칙으로 풀이하며 된다.
*n번 접을 때의 배열 사이즈는 2^n -1이다.
*가장 중앙값은 항상 [0] 이고 ((V) 로 접힐 수 밖에 없는 부분이니까)
0부터 mid-1 의 값들과 mid+1~2^n-2 까지의 값들은 반대로 대칭된다. (1-> 0 / 0->1)
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 | #include <string> #include <vector> #include <iostream> #include <cmath> using namespace std; vector< int > solution( int n) { vector< int > answer; //정중앙을 중심으로 대칭 int size = pow (2, n)-1; vector< int > res(size); res[0] = 0; for ( int i = 1; i < n; i++) { int size = pow (2, i+1)-1; //현재 사이즈 int prev = pow (2, i) -1; res[prev] = 0; int idx = prev; for ( int j = prev-1; j >= 0; j--) { res[++idx] = 1-res[j]; } } answer = res; return answer; } |
<어려운 버전>
2019/08/06 - [BOJ/C++] - [BOJ] 드래곤커브
[BOJ] 드래곤커브
[문제] https://www.acmicpc.net/problem/15685 15685번: 드래곤 커브 첫째 줄에 드래곤 커브의 개수 N(1 ≤ N ≤ 20)이 주어진다. 둘째 줄부터 N개의 줄에는 드래곤 커브의 정보가 주어진다. 드래곤 커브의..
jayrightthere.tistory.com
'Programmers > 프로그래머스' 카테고리의 다른 글
[Programmers] N-Queen (0) | 2020.04.03 |
---|---|
[Programmers] 방문 길이 (0) | 2020.04.03 |
[Programmers] 등굣길 (0) | 2020.04.02 |
[Programmers] 튜플 (python) (0) | 2020.04.01 |
[Programmers] 불량 사용자 (0) | 2020.04.01 |