-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1310.cpp
114 lines (100 loc) · 1.97 KB
/
1310.cpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// 1310. 달리기 코스
// 2021.09.16
// 볼록 껍질
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cmath>
using namespace std;
struct pos
{
long long x, y;
};
vector<pos> v;
// y -> x 오름차순
bool Cmp(pos a, pos b)
{
if (a.y != b.y)
{
return a.y < b.y;
}
else
{
return a.x < b.x;
}
}
long long CCW(pos a, pos b, pos c)
{
return (a.x * b.y + b.x * c.y + c.x * a.y) - (b.x * a.y + c.x * b.y + a.x * c.y);
}
// 0번째 점과 이루는 각도 순 정렬
bool CmpCCW(pos a, pos b)
{
long long cc = CCW(v[0], a, b);
if (cc != 0)
{
return cc > 0;
}
else
{
return (a.x + a.y) < (b.x + b.y);
}
}
long long GetDist(pos a, pos b)
{
long long dx = b.x - a.x;
long long dy = b.y - a.y;
return dx * dx + dy * dy;
}
int main()
{
stack<pos> s;
int n;
cin >> n;
v.resize(n);
for (int i = 0; i < n; i++)
{
cin >> v[i].x >> v[i].y;
}
sort(v.begin(), v.end(), Cmp);
sort(v.begin() + 1, v.end(), CmpCCW);
s.push(v[0]);
s.push(v[1]);
pos first, second;
for (int i = 2; i < n; i++)
{
while (s.size() >= 2)
{
second = s.top();
s.pop();
first = s.top();
if (CCW(first, second, v[i]) > 0)
{
s.push(second);
break;
}
}
s.push(v[i]);
}
// 답을 도출하기 위해 스택에 있는것을 CCW Vector에 옮겨줌
vector<pos> ccwVector;
while (!s.empty())
{
ccwVector.push_back(s.top());
s.pop();
}
long long ans = 0;
for (int i = 0; i < ccwVector.size(); i++)
{
for (int j = i + 1; j < ccwVector.size(); j++)
{
if (ans < GetDist(ccwVector[i], ccwVector[j]))
{
ans = GetDist(ccwVector[i], ccwVector[j]);
}
}
}
cout << ans << endl;
return 0;
}