Cows

Time Limit: 2000MS Memory Limit: 65536K

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

Source

CCC 2007

很显然,这道题是要让我们算出给出点的凸包的面积。综上所述:这是一道凸包的裸板题,我本蒟蒻用的是Graham" role="presentation" style="position: relative;">GrahamGraham扫描法。

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 10005
using namespace std;
struct pot{
    double x,y;
}p[N],vec[N];
inline double cross(pot a,pot b){return a.x*b.y-a.y*b.x;}
inline pot Vector(pot a,pot b){pot c;c.x=a.x-b.x,c.y=a.y-b.y;return c;}
inline double calc(pot *p,int n){
    double ans=0;
    for(int i=1;i<n-1;++i)
        ans+=cross(Vector(p[i],p[0]),Vector(p[i+1],p[0]));
    return ans/2;
}
inline bool cmp(const pot&x,const pot&y){return x.x==y.x?x.y<=y.y:x.x<y.x;}
inline int solve(pot *p,int n,pot *vec){
    sort(p,p+n,cmp);
    int m=0;
    for(int i=0;i<n;++i){
        while(m>1&&cross(Vector(vec[m-1],vec[m-2]),Vector(p[i],vec[m-2]))<=0)--m;
        vec[m++]=p[i];
    }
    int k=m;
    for(int i=n-2;i>=0;--i){
        while(m>k&&cross(Vector(vec[m-1],vec[m-2]),Vector(p[i],vec[m-2]))<=0)--m;
        vec[m++]=p[i];
    }
    if(n>1)m--;
    return m;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i)scanf("%lf%lf",&p[i].x,&p[i].y);
    int m=solve(p,n,vec),ans=0;
    double area=calc(vec,m);
    while(area>=50)area-=50,++ans;
    printf("%d",ans);
}

2018.07.03 POJ 3348 Cows(凸包)的更多相关文章

  1. POJ 3348 Cows 凸包 求面积

    LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...

  2. POJ 3348 - Cows 凸包面积

    求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...

  3. 2018.07.03 POJ 1279Art Gallery(半平面交)

    Art Gallery Time Limit: 1000MS Memory Limit: 10000K Description The art galleries of the new and ver ...

  4. 2018.07.08 POJ 2481 Cows(线段树)

    Cows Time Limit: 3000MS Memory Limit: 65536K Description Farmer John's cows have discovered that the ...

  5. poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 Description ...

  6. POJ 3348 Cows (凸包模板+凸包面积)

    Description Your friend to the south is interested in building fences and turning plowshares into sw ...

  7. POJ 3348 Cows [凸包 面积]

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9022   Accepted: 3992 Description ...

  8. POJ 3348 Cows | 凸包——童年的回忆(误)

    想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...

  9. POJ 3348 Cows | 凸包模板题

    题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...

随机推荐

  1. HTML网页Table解析

    procedure TForm27.Button1Click(Sender: TObject); var doc2: IHTMLDocument2; doc3: IHTMLDocument3; ita ...

  2. UI5-文档-4.22-Expression Binding

    有时预定义的SAPUI5类型不够灵活,您希望在视图中执行简单的计算或格式化——这正是表达式真正有用的地方.我们使用它们根据数据模型中的当前数字格式化价格. Preview The price is n ...

  3. 如何判断int类型相等

    int  a=10: int b=10: a==b  通过==判断两个int值是否相等. if(a==b){ 相等 }else{ 不相等 }

  4. 用java编写一个函数,用于计算桌子的面积,可计算任意边长的桌子

    /* *桌子实体类,有属性和方法 */public class Table {    String name; // 声明桌子名称    Double width; // 声明桌子宽度    Doub ...

  5. Hive—简单窗口分析函数

    hive 窗口分析函数 : jdbc:hive2:> select * from t_access; +----------------+---------------------------- ...

  6. Express 应用生成器

    [Express 应用生成器] 通过应用生成器工具 express 可以快速创建一个应用的骨架. 通过如下命令安装,-g意味着安装在全局目录下: 下面的示例就是在当前工作目录下创建一个命名为 myap ...

  7. 基于Woodstox的StAX 2 (Streaming API for XML)解析XML

    StAX (Streaming API for XML)面向流的拉式解析XML,速度快.占用资源少,非常合适处理大数据量的xml文件. 详细教程和说明可以参见以下几篇文章: 使用 StAX 解析 XM ...

  8. mysql服务器设置其他电脑访问

    解决pc.b想访问pc.a上的mysql而访问不了的问题. 第一步:先在navicat的tools里面选择console 第二步:输入下面的信息: '; 其中wp是登陆数据库的用户名,IP地址是允许访 ...

  9. js input监听兼容事件

    $('#phoneNumber').on('input',function() { var valueP = $(this).attr('value'); if(valueP.length == 11 ...

  10. hdoj1176 免费馅饼(dp 数塔)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176 思路: 这道题不复杂,很明显是个dp题,数据比较大,搜索应该会超时,想到如何初始化,注意细节就差 ...