POJ - 3348Cows ————计算几何(凸包计算)

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


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int MAXN=1e4+5,inf=0x3f3f3f;
struct Pt{
    double x,y;
    Pt(){}
    Pt(double _x,double _y)
    {
        x=_x;
        y=_y;
    }
}p[MAXN],s[MAXN];
int n;
double  dir(Pt p1,Pt p2,Pt p3)
{
    return (p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y);
 } 
double dis(Pt p1,Pt p2)
{
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)-(p1.y-p2.y)*(p1.y-p2.y));
}
bool cmp(Pt p1,Pt p2)
{
    double te=dir(p[0],p1,p2);
    if(te<0)    return 1;
    else if(te==0 && dis(p[0],p1)<dis(p[0],p2)) return 1;
    return 0;
}

double solve()
{
    int pos;
    double minx,miny;
    minx=miny=inf;
    for(int i=0;i<n;i++)
    {
        if(p[i].x<minx||(p[i].x==minx)&&p[i].y<miny)
        {
            minx=p[i].x;
            miny=p[i].y;
            pos=i;
        }
    }
    swap(p[0],p[pos]);
    sort(p+1,p+n,cmp);
    int top=2;
    p[n]=p[0];
    s[0]=p[0];s[1]=p[1];s[2]=p[2];
    for(int i=3;i<=n;i++)
    {
        while(top>=2 && dir(s[top-1],s[top],p[i])>=0)   top--;
        s[++top]=p[i];
    }
    double ans=0;
    for(int i=1;i<top-1;i++)
        ans-=dir(s[0],s[i],s[i+1]);
    return ans/2;
}
int main()
{
    ios::sync_with_stdio(0);
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
            cin>>p[i].x>>p[i].y;
        cout<<(int)solve()/50<<endl;    
    }
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值