Cows POJ - 3348

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 Input4 0 0 0 101 75 0 75 101Sample Output151


#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

const int mt = 10000+5;

struct vec

{

    int x,y;

}ovo[mt],qaq[mt];

int top=0;

inline int read()

{

    int num=0,flag=1;

    char ch;

    do{

        ch=getchar();

        if(ch=='-') flag=-1;

    }while(ch<'0'||ch>'9');

    do{

        num=num*10+ch-'0';

        ch=getchar();

    }while(ch>='0'&&ch<='9');

    return num*flag;

}

vec operator - (vec a,vec b)

{

   vec c;c.x=a.x-b.x;c.y=a.y-b.y;

   return c;

}

int operator * (vec a,vec b)

{

    return a.x*b.y-a.y*b.x;

}

int dis(vec a,vec b)

{

    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);

}

bool cmp(vec a,vec b)

{

    int t=(a-ovo[1])*(b-ovo[1]);

    if(t==0) return dis(a,ovo[1])<dis(b,ovo[1]);

    return t>0;

}

int myabs(int x)

{

    if(x>0) return x;

    return -x;

}

void graham(int n)

{

    int tmp=1;

    for(int i=2;i<=n;i++)

        if(ovo[i].x<ovo[tmp].x||(ovo[i]).x==ovo[tmp].x&&ovo[i].y<ovo[i].y) tmp=i;

    swap(ovo[tmp],ovo[1]);

    sort(ovo+2,ovo+n+1,cmp);

    qaq[++top]=ovo[1],qaq[++top]=ovo[2];

    for(int i=3;i<=n;i++)

      {while((qaq[top]-qaq[top-1])*(ovo[i]-qaq[top-1])<=0) top--;

      qaq[++top]=ovo[i];}

      qaq[top+1]=ovo[1];

}

int main()

{

    int n=read();

    for(int i=1;i<=n;i++) ovo[i].x=read(),ovo[i].y=read();

    graham(n);

    long long ans=0;

    for(int i=1;i<=top;i++)

        ans+=(long long)(qaq[i]*qaq[i+1]);

    printf("%lld\n",myabs(ans)/100);

    return 0;

}



评论

热度(4)