• I


    来源 poj 3348

    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<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include <iomanip>
    #include<cmath>
    #include<float.h> 
    #include<string.h>
    #include<algorithm>
    #define sf scanf
    #define pf printf
    #define mm(x,b) memset((x),(b),sizeof(x))
    #include<vector>
    #include<queue>
    #include<stack>
    #include<map>
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=a;i>=n;i--)
    typedef long long ll;
    const ll mod=1e9+100;
    const double eps=1e-8;
    using namespace std;
    const double pi=acos(-1.0);
    const int inf=0xfffffff;
    struct Point{
        int x,y,temp;
    }p[10005],s[10005];
    int top;
    int direction(Point p1,Point p2,Point p3) { return (p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y); }//´Ó1µ½2µÄÏòÁ¿ºÍ´Ó1µ½3µÄÏòÁ¿£¬Èç¹ûµ½3µÄÏòÁ¿ÔÚµ½2µÄÓұߣ¬¾ÍÊÇ´óÓÚ0µÄ
    double dis(Point p1,Point p2) { return sqrt(1.0*(p2.x-p1.x)*(p2.x-p1.x)+1.0*(p2.y-p1.y)*(p2.y-p1.y)); }
    bool cmp(Point p1,Point p2)//¼«½ÇÅÅÐò 
    {
        int temp=direction(p[0],p1,p2);
        if(temp<0)return true ;
        if(temp==0&&dis(p[0],p1)<dis(p[0],p2))return true;
        return false;
    }
    void Graham(int n)
    {
        int pos,minx,miny;
        minx=miny=inf;
        for(int i=0;i<n;i++)//ÕÒ×îÏÂÃæµÄ»ùµã
            if(p[i].y<miny||(p[i].y==miny&&p[i].x<minx))
            {
                minx=p[i].x;
                miny=p[i].y;
                pos=i;
            }
        swap(p[0],p[pos]);
        sort(p+1,p+n,cmp);
        p[n]=p[0];
        s[0]=p[0];s[1]=p[1];s[2]=p[2];
        top=2;
        for(int i=3;i<=n;i++)
        {
            while(direction(s[top-1],s[top],p[i])>=0&&top>=2)top--;//ËùÒÔÔÚÓұߵĻ°£¬¾ÍÒªÍË»ØÈ¥¸²¸Ç
            s[++top]=p[i] ;
        }
    }
    double area(Point a,Point b,Point c)
    {
    	double x1,x2,x3,x;
    	x1=dis(a,b);
    	x2=dis(a,c);
    	x3=dis(b,c);
    	x=(x1+x2+x3)/2;
    	return sqrt(x*(x-x1)*(x-x2)*(x-x3));
    }
    int main()
    {
    	int n;
    	cin>>n;
    	rep(i,0,n)
    	sf("%d%d",&p[i].x,&p[i].y);
    	Graham(n);
    	double sum=0;
    	rep(i,1,top-1)
    	{
    		sum+=area(s[0],s[i],s[i+1]);
    	}
    	pf("%d",(int)sum/50);
    	return 0;
    }
    
  • 相关阅读:
    树型表的设计 上海
    FTP通讯封装 上海
    线程淡写 上海
    TCP通讯故障 上海
    设计模式引导 上海
    初试Delegate 上海
    c# 扫描端口 上海
    攻读计算机研究生的看法(转载) 上海
    挖掘表字段中的汉字 上海
    新生活运动 上海
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9431508.html
Copyright © 2020-2023  润新知