문제 링크 : https://www.acmicpc.net/problem/15685



x, y 좌표의 최대 범위가 <=100 이였는데 문제 대충읽고 <100으로 알고 풀었다.

그래서 런타임에러와 틀렸습니다를 반복하며 맞왜틀 맞왜틀 하다가 범위를 다시 확인하고 맞았다.



문제 접근

1. 드래곤 커브의 정보를 입력받았다.


2. 드래곤 커브의 세대를 진행해주었다

각 드래곤커브의 정보는 ArrayList로 유지하였고 드래곤 커브가 위치하고 있는 점은 map배열에 표시해주었다.


3. map배열을 순회하며 정사각형의 네 꼭지점이 모두 드래곤커브의 일부인 정사각형의 개수를 세어 출력하였다.





소스 코드


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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
    
    static boolean map[][] = new boolean[101][101];
    static int generation[];
    static ArrayList<Point> curve[];
    static int dy[] = { 0-101 };
    static int dx[] = { 10-10 };
    
    public static void rotate(int index) {
        int curveSize = curve[index].size();
        Point lastP = curve[index].get(curveSize-1);
        
        for(int i=curveSize-2; i>=0; i--) {
            Point tmp = curve[index].get(i);
            int yDif = lastP.y - tmp.y;
            int xDif = lastP.x - tmp.x;
            
            int nextY = lastP.y - xDif;
            int nextX = lastP.x + yDif;
            
            curve[index].add(new Point(nextY, nextX));
            map[nextY][nextX] = true;
        }
        
    }
    
    public static void main(String[] args) {
        int n, x, y, d, g, cnt=0;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        generation = new int[n];
        curve = new ArrayList[n];
        
        // 입력, 0세대 커브 만듦
        for(int i=0; i<n; i++) {
            x = sc.nextInt();
            y = sc.nextInt();
            d = sc.nextInt();
            g = sc.nextInt();
            
            curve[i] = new ArrayList<Point>();
            
            curve[i].add(new Point(y, x));
            map[y][x] = true;
            int ny = y + dy[d];
            int nx = x + dx[d];
            curve[i].add(new Point(ny, nx));
            map[ny][nx] = true;
            
            generation[i] = g;
        }
        
        for(int i=0; i<n; i++) {
            if(generation[i]>0) {
                for(int j=0; j<generation[i]; j++) {
                    rotate(i);
                }
            }
        }
        
        for(int i=0; i<100; i++) {
            for(int j=0; j<100; j++) {
                if(map[i][j] && map[i+1][j] && map[i][j+1&& map[i+1][j+1])
                    cnt++;
            }
        }
        System.out.println(cnt);
    }
}
 
class Point {
    int y;
    int x;
    Point(int y, int x) {
        this.y = y;
        this.x = x;
    }
}
cs


'Algorithm > 백준' 카테고리의 다른 글

백준 17144번 미세먼지 안녕!  (0) 2019.05.03
백준 16235번 나무재테크  (0) 2019.05.03
백준 14891번 톱니바퀴  (0) 2019.04.30
백준 15683번 감시  (0) 2019.04.30
백준 14889번 스타트와 링크  (0) 2019.04.28

+ Recent posts