Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 8753 | Accepted: 3870 |
Description
Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.
However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.
Input
The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and y separated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).
Output
You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.
Sample Input
4
0 0
0 101
75 0
75 101
Sample Output
151
Source
题目链接:http://poj.org/problem?id=3348
题目大意:给n个点,求能组成的最大面积/50
题目分析:凸包模板题,求出凸包后,逆时针的叉积就是一条边和基点组成的三角形面积,全部加起来即可
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const MAX = 1e4 + 5;
int n;
struct POINT {
int x, y;
}p[MAX], stk[MAX], base;
void getBase() {
scanf("%d %d", &p[0].x, &p[0].y);
base.x = p[0].x;
base.y = p[0].y;
int pos = 0;
for (int i = 1; i < n; i ++) {
scanf("%d %d", &p[i].x, &p[i].y);
if (p[i].y < base.y || (p[i].y == base.y && p[i].x < base.x)) {
base.x = p[i].x;
base.y = p[i].y;
pos = i;
}
}
swap(p[0], p[pos]);
}
int getDist(POINT p1, POINT p2) {
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
int getCross(POINT p0, POINT p1, POINT p2) {
return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
bool cmp(POINT p1, POINT p2) {
if (getCross(base, p1, p2) == 0) {
return getDist(base, p1) < getDist(base, p2);
}
if (getCross(base, p1, p2) > 0) {
return true;
}
return false;
}
int main() {
scanf("%d", &n);
getBase();
sort(p + 1, p + n, cmp);
stk[0] = p[0];
stk[1] = p[1];
int top = 1;
for (int i = 0; i < n; i ++) {
while (top > 0 && getCross(stk[top - 1], stk[top], p[i]) <= 0) {
top --;
}
stk[++ top] = p[i];
}
stk[++ top] = p[0];
int ans = 0;
for (int i = 0; i < top; i ++) {
ans += getCross(base, stk[i], stk[i + 1]);
}
printf("%d\n", ans / 100);
}