
1 struct Poi {
2 LL x, y;
3 Poi() {}
4 Poi(LL X, LL Y)
5 : x(X), y(Y) {}
6 bool operator==(const Poi& R) const {
7 return (x == R.x) && (y == R.y);
8 }
9 Poi operator+(const Poi& R) const {
10 return Poi(x + R.x, y + R.y);
11 }
12 Poi operator-(const Poi& R) const {
13 return Poi(x - R.x, y - R.y);
14 }
15 LL operator&(const Poi& R) const {
16 return x * R.x + y * R.y;
17 }
18 LL operator*(const Poi& R) const {
19 return x * R.y - y * R.x;
20 }
21 inline void read() {
22 ::read(x);
23 ::read(y);
24 }
25 };
26 struct Line {
27 Poi A, B;
28 Line() {}
29 Line(Poi a, Poi b)
30 : A(a), B(b) {}
31 };
32 inline LL dis2(Poi A, Poi B) {
33 return (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
34 }
35
36 inline bool ConvexCmp(const Poi& A, const Poi& B) {
37 if(A.x != B.x)
38 return A.x < B.x;
39 return A.y < B.y;
40 }
41 void GetConvex(Poi* a, int n, Poi* p, int& tot) {
42 std::sort(a, a + n, ConvexCmp);
43 p[0] = a[0];
44 tot = 1;
45 for(int i = 1; i < n; i++) {
46 while((tot > 1 && (p[tot - 1] - p[tot - 2]) * (a[i] - p[tot - 1]) <= 0)) {
47 --tot;
48 }
49 p[tot++] = a[i];
50 }
51 int temp = tot;
52 for(int i = n - 2; i >= 0; i--) {
53 while((tot > temp && (p[tot - 1] - p[tot - 2]) * (a[i] - p[tot - 1]) <= 0)) {
54 --tot;
55 }
56 p[tot++] = a[i];
57 }
58 --tot;
59 return;
60 }
总模板