题目描述:http://poj.org/problem?id=3348
解题思路:先求凸包然后求面积。
/*
* 2014.11.28
* Problem: 3348
* Memory: 180K Time: 16MS
* Language: C++ Result: Accepted
*
*/
#include "iostream"
#include "cmath"
#include "algorithm"
#define MAXN 10007
#define EPS 1e-8
using namespace std;
struct Point {
double x, y;
}t[MAXN], p[MAXN];
int nt, n = 0;
double cross(Point a, Point b, Point c) {
double x1 = b.x-a.x, y1 = b.y-a.y;
double x2 = c.x-a.x, y2 = c.y-a.y;
return (x1*y2-x2*y1);
}
bool turnLeft(Point a, Point b, Point c) {
return cross(a, b, c)>=-EPS;
}
bool cmp(Point a, Point b) {
return a.x<b.x || (a.x==b.x && a.y<b.y);
}
void convexHull(int &n, Point p[], int &nt, Point t[]) {
sort(t+1, t+nt+1, cmp);
p[n=1] = t[1];
for (int i=2; i<=nt; i++) {
while (n>=2 && turnLeft(p[n-1], p[n], t[i])) n--;
p[++n] = t[i];
}
int pn = n;
for (int i=nt-1;i>=1;i--) {
while (n>=pn+1 && turnLeft(p[n-1], p[n], t[i])) n--;
p[++n] = t[i];
}
n--;
}
double getArea(Point p[]) {
double ans = 0;
for (int i=2;i<n;i++) {
ans += fabs(cross(p[1], p[i], p[i+1]));
}
return ans*0.5;
}
int main() {
scanf("%d", &nt);
for (int i=1;i<=nt;i++) scanf("%lf %lf", &t[i].x, &t[i].y);
convexHull(n, p, nt, t);
double area = getArea(p);
printf("%d\n", (int)area/50);
return 0;
}