题意 : 就是让你求出凸包面积然后除以50
题解 :
- 凸包的求法
- 面积的求法
说一下面积的求法 : 和凸包的排序方式一样然后逆时针扫一遍凸包把所有的面积全部加起来就可以得到答案了。 (一定要先固定一个极点然后按照极角排序就可以了)
ps : 计算几何输入一定要用scanf;
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
const double eps = 1e-8;
const int maxn = 1e4 + 10;
const double INF = 1e15 + 7;
struct point {
double x,y;
}p[maxn],tu[maxn];
point init;
int n;
double dist (point a,point b) {
return sqrt ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double cross (double x1,double y1,double x2,double y2) {
return x1 * y2 - x2 * y1;
}
bool cmp (point a,point b) {
if (fabs(cross(a.x - init.x, a.y - init.y, b.x - init.x, b.y - init.y)) < eps) {
return dist(a, init) < dist(b, init);
}
else
return cross(a.x - init.x, a.y - init.y, b.x - init.x, b.y - init.y) > 0;
}
int main () {
ios_base :: sync_with_stdio(false);
while (scanf ("%d",&n) != EOF) {
double mix = 0,miy = INF;
int pos = 1;
for (int i = 1;i <= n; ++ i) {
scanf ("%lf%lf",&p[i].x,&p[i].y);
if (miy > p[i].y) {
miy = p[i].y;
pos = i;
mix = p[i].x;
}
else if (fabs (miy - p[i].y) < eps) {
if (mix > p[i].x) {
mix = p[i].x;
pos = i;
}
}
}
swap (p[1],p[pos]);
init = p[1];
sort (p + 2,p + n + 1,cmp);
tu[1] = p[1],tu[2] = p[2],tu[3] = p[3];
int tot = 3;
for (int i = 4;i <= n; ++ i) {
while (tot >= 3) {
point p1,p2,p3;
p1 = tu[tot];
p2 = tu[tot - 1];
p3 = p[i];
if (cross(p1.x - p2.x,p1.y - p2.y , p3.x-p1.x, p3.y - p1.y) < 0) tot --;
else break;
}
tu[++tot] = p[i];
}
init = tu[1];
sort (tu + 2,tu + tot + 1,cmp);
double res = 0;
for (int i = 2;i < tot; ++ i) {
if (i != tot) {
res += cross(tu[i].x - p[1].x, tu[i].y - p[1].y, tu[i + 1].x - p[1].x, tu[i + 1].y - p[1].y);
}
}
int ans = floor(fabs (res) / 100);
printf ("%d\n",ans);
}
return 0;
}