Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- SWEA
- binary search
- 백준
- DP
- math
- Java
- dfs
- 프로그래머스
- 코테
- priorityqueue
- 문자열
- 운동기록
- MySQL
- 코딩테스트
- db
- 이분탐색
- 투포인터
- 문제해결
- 문제풀이
- 러닝일지
- BOJ
- SQL
- oracle
- 자바
- greedy
- 시뮬레이션
- 건강
- BFS
- COS PRO
- 알고리즘
Archives
- Today
- Total
슈콩
[BOJ] 백준 15685 드래곤 커브 본문
[문제]
https://www.acmicpc.net/problem/15685
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int[] dr = {0,-1,0,1};
static int[] dc = {1,0,-1,0};
static boolean[][] map = new boolean[101][101];
static List<Integer> list;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
for(int i=0;i<n;i++) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int g = Integer.parseInt(st.nextToken());
allDir(d,g);
drawDragon(x,y);
}
int result = 0;
for(int i=0;i<100;i++) {
for(int j=0;j<100;j++) {
if(map[i][j] && map[i][j+1] && map[i+1][j] && map[i+1][j+1])
result++;
}
}
System.out.println(result);
}
private static void allDir(int d,int g) {
list = new ArrayList<>();
list.add(d);
for(int i=0;i<g;i++) {
int size = list.size();
for(int k=size-1;k>=0;k--) {
list.add((list.get(k)+1) % 4);
}
}
}
private static void drawDragon(int x,int y) {
map[y][x] = true;
int nr=y,nc=x;
for(int i=0;i<list.size();i++) {
int d = list.get(i);
nr += dr[d];
nc += dc[d];
map[nr][nc] = true;
}
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 16234 인구 이동 (0) | 2025.09.23 |
|---|---|
| [BOJ] 백준 15686 치킨 배달 (0) | 2025.09.23 |
| [BOJ] 백준 2512 예산 (0) | 2025.09.23 |
| [BOJ] 백준 2473 세 용액 (0) | 2025.09.23 |
| [BOJ] 백준 15684 사다리 조작 (0) | 2025.09.23 |