-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvexhull.cpp
More file actions
66 lines (58 loc) · 1.22 KB
/
Copy pathconvexhull.cpp
File metadata and controls
66 lines (58 loc) · 1.22 KB
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
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const ld eps = 1e-12;
const int MAXN = 500000;
int n; // number of points we are considering
struct point{
ll x, y;
point(){}
point(ll xx, ll yy){x=xx, y=yy;}
point operator-(const point &b) const{
return point(x-b.x, y- b.y);
}
ll operator^(const point &b) const{
return x*b.y - y*b.x;
}
bool operator<(const point &b) const{
if(x!=b.x) return x < b.x;
return y < b.y;
}
bool operator==(const point &b) const{
return x == b.x && y == b.y;
}
};
vector<point> hull(vector<point> s){
sort(s.begin(), s.end());
vector<point> up, dn;
for(int i=0; i<s.size(); i++){
while(up.size() > 1 && ((up.back() - up[up.size()-2])^(s[i] - up.back())) > 0){
up.pop_back();
}
up.pb(s[i]);
}
for(int i = s.size() - 1; i>=0; i--){
while(dn.size() > 1 && ((dn.back() - dn[dn.size()-2])^(s[i] - dn.back())) > 0){
dn.pop_back();
}
dn.pb(s[i]);
}
for(int i=1; i<dn.size() - 1; i++){
up.pb(dn[i]);
}
return up;
}
int main(){
return 0;
}