POJ3348 Cows

原题链接:http://poj.org/problem?id=3348
博主的中文题面:
https://www.luogu.org/problemnew/show/T23970

Cows

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.

Sample Input

4
0 0
0 101
75 0
75 101

Sample Output

151

题目大意

求凸包面积

题解

求凸包的板子题,先按x为第一关键字,y为第二关键字排序,然后以左下角的点为起点(显然该点在凸包上),逆时针进行搜索(实际上因为我们排过序,就是遍历而已)。每次加入新元素时,将其与栈顶的两个点进行比较,如果新加入的点在栈顶两元素连线的右侧,那么弹出栈顶元素(根据凸包的定义,要求我们的路径是一直左转的),更新完毕后,再加入新元素即可。
求面积部分与POJ1654一致,最后记得除以50即可AC。

代码
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e4+5;
const int mod=2e3;
struct pt{int x,y;};
bool operator < (const pt &a,const pt &b){return a.x==b.x?a.y<b.y:a.x<b.x;}
pt operator - (pt a,pt b){pt r;r.x=a.x-b.x;r.y=a.y-b.y;return r;}
int operator * (pt a,pt b){return a.x*b.y-a.y*b.x;}
pt p[M],sta[M];
int top,n;
void in()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    scanf("%d%d",&p[i].x,&p[i].y);
}
void tubao()
{
    sort(p+1,p+1+n);
    sta[0]=sta[1]=p[1];
    top=1;
    for(int i=2;i<=n;++i)
    {
        while((sta[top]-sta[top-1])*(p[i]-sta[top-1])>0) --top;
        sta[++top]=p[i];
    }
    for(int i=n-1;i>=1;--i)
    {
        while((sta[top]-sta[top-1])*(p[i]-sta[top-1])>0) --top;
        sta[++top]=p[i];
    }
}
int area(pt a,pt b)
{
    return 1ll*(a.x-b.x)*(a.y+b.y+2*mod);
}
void ac()
{
    long long ans=0;
    tubao();
    for(int i=1;i<top;++i)
    {
        ans+=area(sta[i],sta[i+1]);
    }
    ans=ans>0?ans:-ans;
    printf("%lld",ans/100);
}
int main()
{
    in();ac();
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值