zoukankan      html  css  js  c++  java
  • poj3348 Cow

    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<cstring>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    
    using namespace std;
    
    const int N=10010;
    const double eps=1e-8;
    struct node{
        double x,y;
        node (double xx=0,double yy=0)
        {
            x=xx; y=yy;
        }
    }po[N];
    int sta[N*2],top,n;
    
    node operator + (const node &a,const node &b)
    {
        return node(a.x+b.x,a.y+b.y);
    }
    node operator - (const node &a,const node &b)
    {
        return node(a.x-b.x,a.y-b.y);
    }
    node operator * (const node &a,const double &b)
    {
        return node(a.x*b,a.y*b);
    }
    node operator / (const node &a,const double &b)
    {
        return node(a.x/b,a.y/b);
    }
    
    int dcmp(double x)
    {
        if (fabs(x)<eps) return 0;
        else
        if (x>0) return 1;
        else return -1;
    }
    
    int cmp(const node &a,const node &b)
    {
        if (dcmp(a.x-b.x)!=0) return a.x<b.x;
        else return a.y<b.y; 
    }
    
    double Cross(node a,node b)
    {
        return a.x*b.y-a.y*b.x;
    }
    
    double SS()
    {
        int i;
        double area=0;
        for (i=2;i<top;i++)  //这里要注意是i<top 
            area+=Cross(po[sta[i]]-po[sta[1]],po[sta[i+1]]-po[sta[1]]);
        return fabs(area)/2;
    }
    
    void TuB()
    {
        int i,j;
        top=0;
        for (i=1;i<=n;i++)
        {
            while (top>1&&dcmp(Cross(po[i]-po[sta[top-1]],po[sta[top]]-po[sta[top-1]]))<=0) top--;
            sta[++top]=i;
        }
        int k=top;
        for (i=n-1;i>=1;i--)
        {
            while (top>k&&dcmp(Cross(po[i]-po[sta[top-1]],po[sta[top]]-po[sta[top-1]]))<=0) top--;
            sta[++top]=i;
        }
        if (n>1) top--;
        if (top<3) printf("0");
        else
        {
            double ans=SS();
            printf("%d",(int)ans/50);
        }
        return;
    }
    
    int main()
    {
        scanf("%d",&n);
        for (int i=1;i<=n;i++) 
            scanf("%lf%lf",&po[i].x,&po[i].y);
        sort(po+1,po+1+n,cmp);
        if (n<3) printf("0");
        else TuB();
        return 0;
    }
  • 相关阅读:
    navigateTo防止多次跳转
    vue中的绑定class和微信小程序中的绑定class的区别
    js同步和异步
    本地存储和vuex使用对比
    微信小程序页面跳转区别总结
    CAS-技术专区-认证服务器cas-server搭建
    CAS-技术专区-SSO配置完整案例(静态认证+数据库认证)
    SpringCloud-技术专区-实战案例-Zuul整合OAuth2.0认证服务
    OAuth2.0协议专区-SpringCloud安全-集成OAuth2实现身份认证和单点登录
    OAuth2.0协议专区-SpringCloud微服务实战-基于OAUTH2.0统一认证授权的微服务基础架构
  • 原文地址:https://www.cnblogs.com/wutongtong3117/p/7673615.html
Copyright © 2011-2022 走看看