# BZOJ3707 圈地

OrzOrzOrzOrzOrz

"出题人题解：

 1 /**************************************************************
2     Problem: 3707
3     User: rausen
4     Language: C++
5     Result: Accepted
6     Time:576 ms
7     Memory:16616 kb
8 ****************************************************************/
9
10 #include <cstdio>
11 #include <cmath>
12 #include <algorithm>
13
14 using namespace std;
15 typedef double lf;
16 const int N = 1005;
17 const int M = N * N;
18
19 struct points {
20     lf x, y;
21     points() {}
22     points(lf _x, lf _y) : x(_x), y(_y) {}
23 }p[N];
24 inline bool operator < (const points &a, const points &b) {
25     return a.x < b.x;
26 }
27
28 inline points operator - (const points &a, const points &b) {
29     return points(a.x - b.x, a.y - b.y);
30 }
31
32 inline lf operator & (const points &a, const points &b) {
33     return a.x * b.y - a.y * b.x;
34 }
35
36 struct lines {
37     int p1, p2;
38     lf S;
39     lines() {}
40     lines(int _p1, int _p2, lf _S) : p1(_p1), p2(_p2), S(_S) {}
41 }l[M];
42 inline bool operator < (const lines &a, const lines &b) {
43     return a.S < b.S;
44 }
45
46 int n, tot;
47 int w[N], a[N];
48 lf ans = 1e60;
49
51     int x = 0, sgn = 1;
52     char ch = getchar();
53     while (ch < '0' || '9' < ch) {
54         if (ch == '-') sgn = -1;
55         ch = getchar();
56     }
57     while ('0' <= ch && ch <= '9') {
58         x = x * 10 + ch - '0';
59         ch = getchar();
60     }
61     return sgn * x;
62 }
63
64 inline void calc(int i, int j, int k) {
65     ans = min(ans, fabs((p[i] - p[k]) & (p[j] - p[k])) / 2);
66 }
67
68 int main() {
69     int i, j, p1, p2;
71     for (i = 1; i <= n; ++i)
73     sort(p + 1, p + n + 1);
74     for (i = 1; i <= n; ++i)
75         a[i] = w[i] = i;
76     for (i = 1; i <= n; ++i)
77         for (j = i + 1; j <= n; ++j)
78             l[++tot] = lines(i, j, (p[j].y - p[i].y) / (p[j].x - p[i].x));
79     sort(l + 1, l + tot + 1);
80     for (i = 1; i <= tot; ++i) {
81         p1 = l[i].p1, p2 = l[i].p2;
82         if (w[p1] > w[p2]) swap(p1, p2);
83         if (w[p1] > 1) calc(a[w[p1] - 1], p1, p2);
84         if (w[p2] < n) calc(a[w[p2] + 1], p1, p2);
85         swap(w[p1], w[p2]);
86         swap(a[w[p1]], a[w[p2]]);
87     }
88     printf("%.2lf\n", ans);
89     return 0;
90 }
View Code

（p.s. 话说那些Rank前4是怎么做到的= =内存和时间都很小的说Orz）

posted on 2014-11-22 14:00  Xs酱~  阅读(340)  评论(2编辑  收藏  举报