• poj 3348 Cows 求凸包面积


    题目链接

    大意:

    求凸包的面积。

    #include <iostream>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <stack>
    #include <bitset>
    using namespace std;
    #define pb(x) push_back(x)
    #define ll long long
    #define mk(x, y) make_pair(x, y)
    #define lson l, m, rt<<1
    #define mem(a) memset(a, 0, sizeof(a))
    #define rson m+1, r, rt<<1|1
    #define mem1(a) memset(a, -1, sizeof(a))
    #define mem2(a) memset(a, 0x3f, sizeof(a))
    #define rep(i, n, a) for(int i = a; i<n; i++)
    #define fi first
    #define se second
    typedef pair<int, int> pll;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int mod = 1e9+7;
    const int inf = 1061109567;
    const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
    const int maxn = 1005;
    struct point
    {
        int x,y;
    };
    point a[maxn];
    int st[maxn], top;
    int cross(point p0,point p1,point p2)
    {
        return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
    }
    double dis(point p1,point p2)
    {
        return sqrt((double)(p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
    }
    bool cmp(point p1,point p2)
    {
        int tmp=cross(a[0],p1,p2);
        if(tmp>0) return true;
        else if(tmp==0&&dis(a[0],p1)<dis(a[0],p2)) return true;
        else return false;
    }
    void init(int n)
    {
        int i,k;
        point p0;
        scanf("%d%d",&a[0].x,&a[0].y);
        p0.x=a[0].x;
        p0.y=a[0].y;
        k=0;
        for(i=1;i<n;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
            if( (p0.y>a[i].y) || ((p0.y==a[i].y)&&(p0.x>a[i].x)) )
            {
                p0.x=a[i].x;
                p0.y=a[i].y;
                k=i;
            }
        }
        a[k]=a[0];
        a[0]=p0;
    
        sort(a+1,a+n,cmp);
    }
    void graham(int n)
    {
        int i;
        if(n==1) {top=0;st[0]=0;}
        if(n==2)
        {
            top=1;
            st[0]=0;
            st[1]=1;
        }
        if(n>2)
        {
            for(i=0;i<=1;i++) st[i]=i;
            top=1;
    
            for(i=2;i<n;i++)
            {
                while(top>0&&cross(a[st[top-1]],a[st[top]],a[i])<=0) top--;
                top++;
                st[top]=i;
            }
        }
    }
    int main()
    {
        int n, r;
        while(cin>>n) {
            init(n);
            graham(n);
            double ans = 0;
            for(int i = 0; i<top; i++) {
                ans += (a[st[i]].x*a[st[i+1]].y-a[st[i]].y*a[st[i+1]].x);
            }
            ans += a[st[top]].x*a[st[0]].y-a[st[top]].y*a[st[0]].x;
            ans /= 2;
            cout<<int(ans/50)<<endl;
        }
        return 0;
    }
  • 相关阅读:
    linux的msl
    kubernetes资源调度之LimitRange
    使用setfacl实现子目录继承父目录权限 转载
    k8s glusterfs,GlusterFS Volume 添加ACL支持
    windows10环境下编译python3版pjsua库
    Java单链表反转
    Linux常用命令
    slice()和splice()区别
    js文件三斜杠注释///reference path用途,js文件引用另一个js文件的写法
    【UML】如何记忆UML类图的画法
  • 原文地址:https://www.cnblogs.com/yohaha/p/5257974.html
Copyright © 2020-2023  润新知