티스토리 뷰
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
|
import java.io.*;
import java.util.Scanner;
public class boj_16505 {
static char[][] map;
static int N, length;
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
length = (int)Math.pow(2, N);
map = new char[length][length];
func(0, 0, length);
// print
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
if (j == length - i) break;
if (map[i][j] == '*') bw.write(map[i][j]);
else bw.write(' ');
}
bw.newLine();
}
bw.flush();
bw.close();
}
private static void func(int x, int y, int length) {
// base condition
if (length == 1) {
map[x][y] = '*';
return;
}
// recursion
int newLength = length/2;
func(x, y, newLength);
func(x, y + newLength, newLength);
func(x + newLength, y, newLength);
}
}
|
cs |
- 재귀
- 재귀랑 좀 친해진거 같다.
'PS > boj' 카테고리의 다른 글
boj)5904 - Moo 게임 (0) | 2020.11.15 |
---|---|
boj)2447 - 별 찍기 - 10 (0) | 2020.11.14 |
boj)1992 - 쿼드트리 (0) | 2020.11.13 |
boj)1780 - 종이의 개수 (0) | 2020.11.13 |
boj)17478 - 재귀함수가 뭔가요? (0) | 2020.11.12 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- http
- 드림코딩
- 모던자바스크립트
- 프로그래머스
- REST API
- java
- JPA 연관관계 매핑
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- js array
- 이펙티브자바 아이템59
- JS 딥다이브
- 김영한 http
- 프로그래머스 SQL
- js api
- 백기선 스터디
- Spring Security
- 이펙티브자바 아이템60
- BOJ
- HTTP 완벽 가이드
- 이펙티브자바
- 김영한 JPA
- ㅇㄷㅇㅈ
- 패스트캠퍼스 컴퓨터공학 완주반
- 킹수빈닷컴
- js promise
- 백준
- GCP
- dreamcoding
- 이펙티브자바 스터디
- HTTP 완벽가이드
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함