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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#include <stack> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const int MAXN = 10005; const double MAXD = 1e9; const double ACCUR = 1e-9; struct node { double x, y; bool operator < (const node n) const { if (abs(y-n.y) < ACCUR) return x < n.x; else return y < n.y; } bool operator == (const node n) const { return (abs(x-n.x) < ACCUR) && (abs(y-n.y) < ACCUR); } void operator = (const node n) { x = n.x; y = n.y; } }; struct vect { double x, y; void operator = (const vect v) { x = v.x; y = v.y; } double operator *(const vect v) const { return x*v.y - y*v.x; } }; node p0; bool equal (const double d1, const double d2) { return abs(d1-d2) < ACCUR; } vect vform(const node n1, const node n2) { vect tmpv; tmpv.x = n2.x - n1.x; tmpv.y = n2.y - n1.y; return tmpv; } double vlen(const vect v) { return sqrt(v.x*v.x+v.y*v.y); } double vcos(const vect v1, const vect v2) { return (v1*v2)/(vlen(v1)*vlen(v2)); }
bool cmpp (const node p1, const node p2) { vect v1, v2; v1 = vform(p0, p1); v2 = vform(p0, p2); if (equal(v1*v2,0)) { return vlen(v1) < vlen(v2); } else { return v1*v2 > 0; } }
bool cmpv (const vect v1, const vect v2) { return (v1*v2 > 0) || equal(v1*v2,0); } double area (const node n1, const node n2, const node n3) {
vect v1, v2; v1 = vform(n1, n2); v2 = vform(n1, n3); return abs(v1*v2)/2; } node p[MAXN]; stack <node> bs; int main() { int n; p0.x = p0.y = MAXD; scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%lf%lf", &(p[i].x), &(p[i].y)); if(p[i] < p0) { p0 = p[i]; } } sort(p,p+n,cmpp); bs.push(p[0]); bs.push(p[1]); int j = 2; while(j < n) { node p1, p2; p2 = bs.top(); bs.pop(); p1 = bs.top(); vect v1, v2; v1 = vform(p1,p2); v2 = vform(p2,p[j]); if(cmpv(v1,v2)) { bs.push(p2); bs.push(p[j]); ++j; } }
double ans = 0; node fp, np, ep; fp = bs.top(); bs.pop(); np = bs.top(); bs.pop(); while(!bs.empty()) { ep = bs.top(); bs.pop(); ans += area(fp,np,ep); np = ep; } printf("%d\n", (int)ans/50); return 0; }
|