(์ž๋ฐ”) ๋ฐฑ์ค€ 7420๋ฒˆ : ๋งน๋… ๋ฐฉ๋ฒฝ

์ด๊ฑฐ ๋ถ„๋ช… ์–ด๋””์„œ ๋ณธ ๋‚ด์šฉ์ด๊ธธ๋ž˜ ๋ƒ…๋‹ค ์‹œ๋„ํ•ด๋ดค๋‹ค. ํ™•์ธํ•ด๋ณด๋‹ˆ ์ปจ๋ฒก์Šค ํ— ๋ฌธ์ œ ํ•˜๋‚˜๋ฐ–์— ์•ˆํ’€์—ˆ๋”๋ผ.. ์ƒ๊ฐ๋ณด๋‹ค ์ธ์ƒ๊นŠ์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด์—ˆ๋‚˜๋ณด๋‹ค. ๋‹ค์Œ์ฃผ์— ๋„์ฟ„๊ฐ„๋‹ค... ์Šคํ‚ค๋Š” ํƒˆ๊นŒ ๋ง๊นŒ ๊ณ ๋ฏผ์ค‘!  ํƒ”๋‹ค๊ฐ€ ์‚ฌ๊ณ ๋‚ด์„œ ํŒŒ์‚ฐํ•˜๋Š”๊ฑด ์•„๋‹์ง€..
๊ตํ™˜ํ•™์ƒ์ด ๊ณง ๋๋‚˜์„œ ์ง€๊ธˆ์€ ํ•ด์•ผํ• ๊ฒŒ ๋งŽ๋‹ค... ์„œ๋ฅ˜๋งŽ๊ณ , ํŒ€ํ”Œ๋งŽ๊ณ , ๋ฐœํ‘œ๋งŽ๋‹ค...๋ฐœํ‘œ์ค€๋น„...๐Ÿฅฒ

 



๋ฌธ์ œ 

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

๋ฌธ์ œ ์ดํ•ด
 
- ๊ฑด๋ฌผ๋“ค์ด ์ฃผ์–ด์ง€๊ณ  ์ด ๊ฑด๋ฌผ๋“ค์„ ํฌํ•จํ•˜๋Š” ๋ฐฉ๋ฒฝ์„ ์ง“๋Š”๋‹ค. ์ปจ๋ฒก์Šค ํ—์ด๋‹ค.
- ๋ฐฉ๋ฒฝ์€ ๊ฑด๋ฌผ๋“ค๊ณผ L ๊ฑฐ๋ฆฌ ์ด์ƒ ๋–จ์–ด์ ธ์žˆ์–ด์•ผํ•œ๋‹ค. ์ปจ๋ฒก์Šค ํ— ์˜ ๊ฒฐ๊ณผ์—์„œ L ๊ฑฐ๋ฆฌ์”ฉ ๋„“ํžŒ๋‹ค?
- ๋ฐฉ๋ฒฝ์˜ ์ตœ์†Œ๊ธธ์ด๋Š” ๋ฌด์—‡์ธ๊ฐ€.
 
 
์ฝ”๋“œ ์„ค๋ช…
- ์ดˆ๋ฐ˜์— ํ‹€๋ฆฐ ๋ถ€๋ถ„
     1. ์ปจ๋ฒก์Šค ํ—์—์„œ L ๋งŒํผ์„ x,y์— ๊ฐ๊ฐ ๋”ํ•˜๊ฑฐ๋‚˜ ๋นผ์„œ ํŒฝ์ฐฝ์‹œํ‚ด → ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ตœ์†Œ ๊ธธ์ด๋ณด๋‹ค ๋” ๋‚˜์˜ด. ๊ฐ ๊ฐ๋„์— ๋Œ€ํ•œ ํ˜ธ๋ฅผ ๊ณ„์‚ฐํ•ด ๋”ํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด๋จ..
         

     2. ๊ฐ๋„ ๊ธฐ์ค€ ์ •๋ ฌ์„ ํ•  ๋•Œ, ๊ธฐ์ค€์ ๊ณผ ํ•จ๊ป˜ ์ •๋ ฌํ•ด๋ฒ„๋ ค์„œ ์„ž์ž„.  → ๊ธฐ์ค€์ ์„ ์Šคํƒ์—์„œ ์ œ๊ฑฐํ•˜๊ณ  ์ง„ํ–‰ํ•จ.

 
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
82
83
84
85
86
87
88
89
90
91
92
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.StringTokenizer;
 
public class B_7420 {
    static class Point {
        int x, y;
 
        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
 
        static int crossProduct(Point p, Point q, Point r) {
            return (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x);
        }
    }
 
    static int distance(Point p1, Point p2) {
        return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
    }
 
    static List<Point> grahamScan(List<Point> points) {
        if (points.size() < 3)
            return points;
 
        Point start = points.get(0);
        for (Point p : points) {
            if (p.y < start.y || (p.y == start.y && p.x < start.x))
                start = p;
        }
 
        Point finalStart = start;
        points.remove(start);  
 
        points.sort((p1, p2) -> {
            long cp = Point.crossProduct(finalStart,p1,p2);
            if (cp == 0)
                return Long.compare(distance(finalStart, p1), distance(finalStart, p2));
            return cp > 0 ? -1 : 1;
        });
 
        Stack<Point> stack = new Stack<>();
        stack.push(finalStart);
        for (Point p : points) {
            while (stack.size() > 1 && Point.crossProduct(stack.get(stack.size() - 2), stack.peek(), p) <= 0) {
                stack.pop();
            }
            stack.push(p);
        }
        return new ArrayList<>(stack);
    }
 
    static double Line(List<Point> hull) {
        double line = 0;
        int n = hull.size();
        for (int i = 0; i < n; i++) {
            Point a = hull.get(i);
            Point b = hull.get((i + 1) % n);
            double dx = b.x - a.x;
            double dy = b.y - a.y;
            double length = Math.sqrt(dx * dx + dy * dy);
            line += length;
        }
        return line;
    }
 
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int L = Integer.parseInt(st.nextToken());
 
        List<Point> points = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(br.readLine());
            int x = Integer.parseInt(st.nextToken());
            int y = Integer.parseInt(st.nextToken());
            points.add(new Point(x, y));
        }
 
        List<Point> hull = grahamScan(points);
        double straightLength = Line(hull);
        double cornerLength = 2 * Math.PI * L;
 
        System.out.println(Math.round(straightLength + cornerLength));
    }
}
 
cs