슈콩

[BOJ] 백준 15685 드래곤 커브 본문

Algorithms/Baekjoon

[BOJ] 백준 15685 드래곤 커브

shukong 2025. 9. 23. 19:11

[문제]

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