题意
求出凸包的面积/50。
思路
用 g r a h a m graham graham算法算出凸包的点,然后再用叉积算出多边形的面积就好了。
代码
#include<cmath>
#include<cstdio>
#include<algorithm>
struct P{
double x, y, q;
}p[10001];
int s[10001], top;
int cmp(P x, P y) {
return x.q < y.q;
}
double CP(P a, P b, P c) {
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
double dis(P a, P b) {
return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
}
int main() {
int n;
scanf("%d", &n);
int g = 1;
for (int i = 1; i <= n; i++) {
scanf("%lf %lf", &p[i].x, &p[i].y);
if (p[i].y < p[g].y || (p[i].y == p[g].y && p[i].x < p[g].x))
g = i;
}
std::swap(p[1], p[g]);
for (int i = 2; i <= n; i++) {
p[i].x -= p[1].x;
p[i].y -= p[1].y;
p[i].q = atan2(p[i].y, p[i].x);
}
std::sort(p + 2, p + 1 + n, cmp);
p[1].x = 0;
p[1].y = 0;
for (int i = 1; i <= 3; i++)
s[i] = i;
top = 3;
for (int i = 4; i <= n; i++) {
while (top >= 3 && (CP(p[s[top - 1]], p[s[top]], p[i]) <= 0))
top--;
s[++top] = i;
}
double ans = 0;
for (int i = 2; i < top; i++)
ans += 0.5 * CP(p[1], p[s[i]], p[s[i + 1]]);
printf("%d", abs(ans) / 50);
}