# BZOJ1670 [Usaco2006 Oct]Building the Moat护城河的挖掘

 1 /**************************************************************
2     Problem: 1670
3     User: rausen
4     Language: C++
5     Result: Accepted
6     Time:16 ms
7     Memory:900 kb
8 ****************************************************************/
9
10 #include <cstdio>
11 #include <cmath>
12 #include <algorithm>
13
14 #define points P
15 using namespace std;
16 typedef long long ll;
17 const int N = 5005;
18 int n, top;
19 double ans;
20 struct points{
21     int x, y;
22 }p[N], s[N];
23
24 inline ll operator * (const P a, const P b){
25     return a.x * b.y - a.y * b.x;
26 }
27
28 inline P operator - (const P a, const P b){
29     P tmp;
30     tmp.x = a.x - b.x, tmp.y = a.y - b.y;
31     return tmp;
32 }
33
34 inline ll Sqr(const ll x){
35     return x * x;
36 }
37
38 inline ll dis(const P a, const P b){
39     return Sqr(a.x - b.x) + Sqr(a.y - b.y);
40 }
41
42 inline bool operator < (const P a, const P b){
43     ll tmp = (a - p[1]) * (b - p[1]);
44     return tmp == 0 ? dis(p[1], a) < dis(p[1], b) : tmp > 0;
45 }
46
48     int x = 0, sgn = 1;
49     char ch = getchar();
50     while (ch < '0' || ch > '9'){
51         if (ch == '-') sgn = -1;
52         ch = getchar();
53     }
54     while (ch >= '0' && ch <= '9'){
55         x = x * 10 + ch - '0';
56         ch = getchar();
57     }
58     return sgn * x;
59 }
60
61 int work(){
62     int k = 1;
63     for (int i = 2; i <= n; ++i)
64         if (p[i].y < p[k].y || (p[i].y == p[k].y && p[i].x < p[k].x)) k = i;
65     swap(p[1], p[k]);
66     sort(p + 2, p + n + 1);
67     top = 2, s[1] = p[1], s[2] = p[2];
68     for (int i = 3; i <= n; ++i){
69         while ((s[top] - s[top - 1]) * (p[i] - s[top]) <= 0) --top;
70         s[++top] = p[i];
71     }
72     s[top + 1] =  p[1];
73     for (int i = 1; i <= top; ++i)
74         ans += sqrt(dis(s[i], s[i + 1]));
75 }
76
77 int main(){
83 }