Cows(凸包面积)

来源:互联网 发布:唱给自己的歌网络战队 编辑:程序博客网 时间:2024/06/05 07:37
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 9628 Accepted: 4221

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 nextn lines contain the integer coordinates of each tree given as two integersx 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

40 00 10175 075 101

Sample Output

151代码:
#include<map>#include<cmath>#include<vector>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;struct node{   int x;   int y;}p[10005],P[10005];int multi(node A,node B,node C){    return (B.x-A.x)*(C.y-A.y)-(C.x-A.x)*(B.y-A.y);}double len(node A,node B){    return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));}bool cmp(node A,node B){    double pp=multi(p[0],A,B);    if(pp>0) return true;    if(pp<0) return false;   return len(p[0],A)<len(p[0],B);}int main(){    int n;    while(~scanf("%d",&n)){    for(int i=0;i<n;i++)    {        scanf("%d%d",&p[i].x,&p[i].y);        if(p[i].y<p[0].y)            swap(p[i],p[0]);        if(p[i].y==p[0].y&&p[i].x<p[0].x)            swap(p[i],p[0]);    }    if(n<3)    {        printf("0\n");    }    else    {    sort(p+1,p+n,cmp);    P[0]=p[0];    P[1]=p[1];    int tot=1;    for(int i=2;i<n;i++)    {        while(tot>0&&multi(P[tot-1],P[tot],p[i])<=0) tot--;        tot++;        P[tot]=p[i];    }    double sum=0;  //求面积    for(int i=1;i<tot;i++)    sum+=abs(multi(P[0],P[i],P[i+1]));    printf("%d\n",(int)sum/100);  } }}


原创粉丝点击