POJ3348——Cows

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 xand 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

先求凸包再求面积,面积是叉积的一半、


///凸包,graham—scan

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>

using namespace std;

int stack[10100];

struct point
{
int x,y;
}list[10100];

int cross(point p0,point p1,point p2)//叉积的计算
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}

double dist(point p1,point p2)
{
return sqrt(double((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y)));
}

int cmp(point a,point b)
{
int cur=cross(a,b,list[0]);
if(cur>0)
return 1;
else if(cur==0 && dist(a,list[0]) <dist(b,list[0]))
return 1;
else
return 0;
}

void init(int n)
{
int i,k;
point p0;
scanf("%d%d",&list[0].x,&list[0].y);
p0.x=list[0].x;
p0.y=list[0].y;
k=0;
for(i=1;i<n;i++)
{
scanf("%d%d",&list[i].x,&list[i].y);
if((list[i].y<p0.y) || (list[i].y==p0.y)&&(list[i].x<p0.x))
{
p0.x=list[i].x;
p0.y=list[i].y;
k=i;
}
}
list[k]=list[0];
list[0]=p0;
sort(list+1,list+n,cmp);
}

int graham(int n)
{
int i,top;
if(n==1)
{
top=0;
stack[top]=0;
}
else if(n==2)
{
top=1;
stack[0]=0;
stack[1]=1;
}
else
{
stack[0]=0;
stack[1]=1;
top=1;
for(i=2;i<n;i++)
{
while(top>0 && cross(list[stack[top-1]],list[stack[top]],list[i])<=0 )
top--;
top++;
stack[top]=i;
}
}
return top;
}

int main()
{
int n;
while(~scanf("%d",&n))
{
init(n);
int top=graham(n);
double area=0;
if(n<3)
printf("0\n");
else
{
for(int i=2;i<=top;i++)
area+=fabs(cross(list[0],list[stack[i]],list[stack[i-1]]));
printf("%d\n",(int)area/100);
}
}
return 0;
}


你可能感兴趣的:(POJ3348——Cows)