hdu 1348 Wall凸包

转自https://www.cnblogs.com/jbelial/archive/2011/08/05/2128625.html



double Multiply(POINT p1 , POINT p2 , POINT p3) // 叉积 
{
       return ( (p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x) ) ;
}
 for ( i = 3 ; i <= n ; ++ i )
     {
         while (Multiply(result[top - 1] , result[top] , tree[i]) <= 0 )
               top -- ;                          //出栈
          result[top + 1].x = tree[i].x ;
          result[top + 1].y = tree[i].y ;
          top ++ ;
     }


#include <iostream>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef class Node{
    public:
        LL x,y;
    bool operator<(Node a)
    {
        if(x==a.x) return y<a.y;
        else return x<a.x;
    }
}node;
node a[1005],b[1005];
int k=0;
node findmax1(node t1,node t2)
{
    int i=0,j,max=0;
    while(a[i].x<t1.x) i++;
    for(i;a[i].x<=t2.x;i++)
    {
        if(a[i].y<0) continue;
        long long aa=t1.x*t2.y+a[i].x*t1.y+t2.x*a[i].y-a[i].x*t2.y-t2.x*t1.y-t1.x*a[i].y;
        if(abs(aa)>max)
        {
            max=abs(aa);
            j=i;
        }
    }
    return a[j];
}
node findmax2(node t1,node t2)
{
    int i=0,j,max=0;
    while(a[i].x<t1.x) i++;
    
    for(i;a[i].x<=t2.x;i++)
    {
        
        if(a[i].y>0) continue;
        
        
        long long aa=t1.x*t2.y+a[i].x*t1.y+t2.x*a[i].y-a[i].x*t2.y-t2.x*t1.y-t1.x*a[i].y;
        if(abs(aa)>max)
        {
            max=abs(aa);
            j=i;
        }
    }
    return a[j];
}
void Convex_Hullup(node t1,node t2)
{    
    node t3;
    t3=findmax1(t1,t2);
    if(t3.x!=t2.x||t3.y!=t2.y)
    {b[++k].x=t3.x;
    b[k].y=t3.y;
    }
    Convex_Hullup(t1,t3);
    Convex_Hullup(t3,t2);
}
void Convex_Hulldown(node t1,node t2)
{    
    node t3;
    t3=findmax2(t1,t2);
    if(t3.x!=t2.x||t3.y!=t2.y)
    {b[++k].x=t3.x;
    b[k].y=t3.y;
    }
    Convex_Hulldowm(t1,t3);
    Convex_Hulldowm(t3,t2);
}
int dis(node t1,node t2)
{
    return (t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y);
}
int main()
{
    int num,n,d;
    cin>>num;
    
    while(num--)
    {
        cin>>n>>d;
        k=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i].x>>a[i].y;
        }
        sort(a,a+n);
        Convex_Hullup(a[0],a[n-1]);
        Convex_Hulldown(a[0],a[n-1]);
        double sum=0;
        for(int i=1;i<=k;i++)
        {
            sum+=sqrt(dis(b[i],b[i-1]));
        }
        
        
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值