zoukankan      html  css  js  c++  java
  • POJ 3348 Cows [凸包 面积]

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

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


    标准模板题
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <vector>
    using namespace std;
    typedef long long ll;
    const int N=1e4+5;
    const double eps=1e-8;
    const double pi=acos(-1);
    
    inline int read(){
        char c=getchar();int x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
        return x*f;
    }
    
    inline int sgn(double x){
        if(abs(x)<eps) return 0;
        else return x<0?-1:1;
    }
    
    struct Vector{
        double x,y;
        Vector(double a=0,double b=0):x(a),y(b){}
        bool operator <(const Vector &a)const{
            //return x<a.x||(x==a.x&&y<a.y);
            return sgn(x-a.x)<0||(sgn(x-a.x)==0&&sgn(y-a.y)<0);
        }
    };
    typedef Vector Point;
    Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
    Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
    Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);}
    Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
    bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==0&&sgn(a.y-b.y)==0;}
    
    double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
    double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
    int ConvexHull(Point p[],int n,Point ch[]){
        sort(p+1,p+1+n);
        int m=0;
        for(int i=1;i<=n;i++){
            while(m>1&&sgn(Cross(ch[m]-ch[m-1],p[i]-ch[m-1]))<=0) m--;
            ch[++m]=p[i];
        }
        int k=m;
        for(int i=n-1;i>=1;i--){
            while(m>k&&sgn(Cross(ch[m]-ch[m-1],p[i]-ch[m-1]))<=0) m--;
            ch[++m]=p[i];
        }
        if(n>1) m--;
        return m;
    }
    double Area(Point p[],int n){
        double s=0;
        for(int i=2;i<n;i++) s+=Cross(p[i]-p[1],p[i+1]-p[1]);
        return s/2;
    }
    int n,x,y;
    double ans;
    Point p[N],ch[N];
    int main(int argc, const char * argv[]) {
        n=read();
        for(int i=1;i<=n;i++) p[i].x=read(),p[i].y=read();
        int m=ConvexHull(p,n,ch);
        printf("%d",int(Area(ch,m))/50);
        return 0;
    }
  • 相关阅读:
    PHP面向对象----- 类的自动加载
    PHP基础知识------页面静态化
    Laravel 开发环境搭建
    jenkins相关学习
    markdown语法学习强化
    bind 使用和配置记录
    关于整形和浮点型的格式输出
    函数体中定义的结构体和类型
    Volatile & Memory Barrier
    各种简单排序算法模版
  • 原文地址:https://www.cnblogs.com/candy99/p/6354455.html
Copyright © 2011-2022 走看看