POJ3348-Cows

Cows
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 6595 Accepted: 2987

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

4
0 0
0 101
75 0
75 101

Sample Output

151
//AC代码
/*
题意:给你n颗树的点,让你帮忙以这些树为点建一个最大的篱笆养牛,并且一头牛要占50平方的面积,问你最多能养几头牛
此题先用凸包算出用来围成篱笆的点(最外围树的坐标),然后用多边形面积公式算出凸包的面积最后除以50取整就行了
*/

#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<cmath>
const double eps=1e-8;
const double PI=3.1415926;
const int Max=1001;
#define zero(x) (((x)>0?(x):-(x))<eps)
using namespace std;
int sign(double x)
{
    return (x>eps)-(x<-eps);
}
typedef struct Node
{
    double x;
    double y;
}point;
point list[Max],stack[Max];
double x[Max];
double y[Max];
int n;
int top;
double xmult(point p0,point p1,point p2)
{
	return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double Distance(point p1,point p2)// 返回两点之间欧氏距离
{
	return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
bool cmp(point p1,point p2)
{
    double temp;
    temp=xmult(list[0],p1,p2);
    if(temp>0)
        return true;
    if(temp==0&&(Distance(list[0],p1)<Distance(list[0],p2)))
        return true;
    return false;
}
void convex_hull()//凸包模板
{
    int i;
    for(i=1;i<n;i++)
    {
        point temp;
        if((list[i].y<list[0].y)||(list[i].y==list[0].y&&list[i].x<list[0].x))
            swap(list[0],list[i]);
    }
    sort(list+1,list+n,cmp);
    top=1;
    stack[0]=list[0];
    stack[1]=list[1];
    for(i=2;i<n;i++)
    {
        while(top>=1&&xmult(stack[top-1],stack[top],list[i])<=0)
            top--;
        top++;
        stack[top]=list[i];
    }
}
int main()
{
    int m,i,j,num;
    double A;
    //freopen("D:\\in.txt","r",stdin);
    //while(1)
    //{
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>list[i].x>>list[i].y;
        }
        convex_hull();
        A=0;//多边形面积
        //------------多边形面积公式-------------
        x[0]=y[0]=0;
        m=top+1;
        for(i=0;i<m;i++)//注意凸包模板一定是逆时针扫描得到的
        {//因为这个多边形面积公式也是按逆时针逐个点计算,如果凸包模板是顺时针算的那么最后算出的面积一定是负的
            x[i+1]=stack[i].x;
            y[i+1]=stack[i].y;
            A+=(x[i]*y[i+1]-x[i+1]*y[i]);
        }
        A+=x[m]*y[1]-x[1]*y[m];
        A/=2.0;
        //------------多边形面积公式-------------
        num=int(A/50);
        cout<<num<<endl;
    //}
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值