Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
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
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[BAEKJOON] 15685. 드래곤 커브 본문

acmicpc

[BAEKJOON] 15685. 드래곤 커브

코드와이 2021. 8. 10. 01:31

 

문제링크

https://www.acmicpc.net/problem/15685

 

15685번: 드래곤 커브

첫째 줄에 드래곤 커브의 개수 N(1 ≤ N ≤ 20)이 주어진다. 둘째 줄부터 N개의 줄에는 드래곤 커브의 정보가 주어진다. 드래곤 커브의 정보는 네 정수 x, y, d, g로 이루어져 있다. x와 y는 드래곤 커

www.acmicpc.net

 

package acmicpc.Gold4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class 드래곤_커브 {
	
	static int[][] check;
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		
		int n = Integer.parseInt(br.readLine());
		
		check = new int[102][102];
		int x, y, d, g;
		
		// 좌표들을 기억할 리스트
		List<int[]> list;
		int[] dr = {0, -1, 0, 1};
		int[] dc = {1, 0, -1, 0};
		for(int i = 0 ; i < n ; i++) {
			st = new StringTokenizer(br.readLine());
			
			y = Integer.parseInt(st.nextToken());
			x = Integer.parseInt(st.nextToken());
			d = Integer.parseInt(st.nextToken());
			g = Integer.parseInt(st.nextToken());
			list = new ArrayList<>();
			 
			check[x][y] = 1;
			check[x + dr[d]][y + dc[d]] = 1;
			
			list.add(new int[] {x,y});
			list.add(new int[] {x + dr[d],y + dc[d]});
			
			int[] vertex = new int[] {x + dr[d],y + dc[d]};
			
			// g 세대만큼 커브
			for(int j = 0 ; j < g ; j++) {
				
				int size = list.size();
				int q[], nr, nc;
				int tmp[] = new int[2];
				
				for(int k = 0 ; k < size ; k++) {
					
					q = list.get(k);
					nr = vertex[0] + (q[1] - vertex[1]);
					nc = vertex[1] - (q[0] - vertex[0]);
					
					// 맨 처음 좌표가 다음 세대에서 마지막 꼭지점이 된다.
					if(k == 0) {
						tmp[0] = nr;
						tmp[1] = nc;
					}
					if(nr < 0 || nc < 0 || nr >= 102 || nc >= 102) continue;
					
					list.add(new int[] {nr, nc});
					check[nr][nc] = 1;
					
				}
				
				// vertex 을 새로운 꼭지점으로 최신화
				vertex[0] = tmp[0];
				vertex[1] = tmp[1];
				
			}
		}
		
		System.out.println(square());
		
	}
	
	// 사각형 카운트
	public static int square() {
		
		int sum = 0;
		
		for(int i = 0 ; i < 101 ; i++) {
			for(int j = 0 ; j < 101 ; j++) {
				if(check[i][j] == 1 && check[i + 1][j] == 1 && check[i][j + 1] == 1 && check[i + 1][j + 1] == 1 ) sum++;
			}
		}
		
		return sum;
	}

}

'acmicpc' 카테고리의 다른 글

[BAEKJOON] 1339. 단어수학  (0) 2021.08.14
[BAEKJOON] 1967. 트리의 지름  (0) 2021.08.10
[BAEKJOON] 1806. 부분합  (0) 2021.08.07
[BAEKJOON] 2573. 빙산  (0) 2021.08.06
[BAEKJOON] 1707. 이분 그래프  (0) 2021.08.06