Cows_poj3348_计算几何

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

Analysis


裸的凸包,求凸包面积用叉积/2

Code


#include <algorithm>
#include <stdio.h>
#include <cmath>
using namespace std;
struct pos
{
    int x,y;
    bool operator<(pos a)
    {
        return a.x<x||a.x==x&&a.y<y;
    }
}t[10001];
int s[10001];
double cros(pos a,pos b,pos c)
{
    return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
double dist(pos a,pos b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(pos a,pos b)
{
    return (cros(a,b,t[0])>0)||((cros(a,b,t[0])==0)&&(dist(a,t[0])<dist(b,t[0])));
}
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
        scanf("%d%d",&t[i].x,&t[i].y);
        if (t[i]<t[0])
        {
            pos tmp=t[i];
            t[i]=t[0];
            t[0]=tmp;
        }
    }
    sort(t+1,t+n,cmp);
    int top=3;
    s[1]=0;
    s[2]=1;
    s[3]=2;
    for (int i=3;i<n;i++)
    {
        while (top>2&&cros(t[i],t[s[top]],t[s[top-1]])>=0)
            top--;
        s[++top]=i;
    }
    double ans=0;
    for (int i=1;i<top;i++)
        ans+=cros(t[s[i]],t[s[i+1]],t[s[0]])/2.0;
    if (ans<0)
        ans=-ans;
    printf("%d\n",(int)(ans/50.0));
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值