【BZOJ】2829: 信用卡凸包-凸包

传送门:bzoj2829


题解

太zz了,这么水的题都没想出来。。。

如果是矩形,凸包上的点一定都是矩形的顶点, g r a h a m graham graham求出凸包后将每个顶点的尖角转成圆弧,贡献不好算。。。

于是将矩形的顶点转成四个 1 4 \frac 14 41圆的圆心,求出凸包周长后+一个圆的周长即可。


代码

直接贴黄学长的了=_=

#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rad 100000000
#define inf 1000000000
#define ll long long 
#define eps 1e-8
#define pa pair<ll,int>
#define pi acos(-1)
using namespace std;
double ans;
int n,cnt,top;
double a,b,r;
double sqr(double x)
{
    return x*x;
}
struct P{
    double x,y;
    P(double _x=0,double _y=0){x=_x;y=_y;}
    friend P operator-(P a,P b){
        return P(a.x-b.x,a.y-b.y);
    }
    friend double operator*(P a,P b){
        return a.x*b.y-a.y*b.x;       
    }
    friend bool operator<(P a,P b){
        if(fabs(a.y-b.y)<eps)return a.x<b.x;
        return a.y<b.y;
    }
    friend double dis2(P a){
        return sqr(a.x)+sqr(a.y);       
    }
}p[400005],q[400005];
struct rec{
    double x,y,angle;     
}o[100005];
void print(P a)
    {
        printf("%.2lf %.2lf\n",a.x,a.y);
    }
P move(P a,double d,double A)
{
    return P(a.x+d*cos(A),a.y+d*sin(A));
}
bool cmp(P a,P b)
{
    if(fabs((a-p[1])*(b-p[1]))<eps)return dis2(p[1]-a)<dis2(p[1]-b);
    return (a-p[1])*(b-p[1])>0;
}
void graham()
{
    for(int i=1;i<=cnt;i++)
        if(p[i]<p[1])swap(p[i],p[1]);
    sort(p+2,p+cnt+1,cmp);
    for(int i=1;i<=cnt;i++)
    {
        while(top>1&&(q[top]-q[top-1])*(p[i]-q[top-1])<-eps)
           top--;
        q[++top]=p[i];
    }
}
void build()
{
    for(int i=1;i<=n;i++)
        for(int k=0;k<4;k++)
        {
            P t=move(P(o[i].x,o[i].y),b/2,o[i].angle+k*pi/2);
            p[++cnt]=move(t,a/2,o[i].angle+(k+1)*pi/2);
            swap(a,b);
        }
}
void solve()
{
    q[top+1]=q[1];
    for(int i=1;i<=top;i++)
        ans+=sqrt(dis2(q[i]-q[i+1]));
}
int main()
{
    scanf("%d",&n);
    scanf("%lf%lf%lf",&a,&b,&r);a-=2*r;b-=2*r;
    ans+=2*pi*r;
    for(int i=1;i<=n;i++)
        scanf("%lf%lf%lf",&o[i].x,&o[i].y,&o[i].angle);
    build();
    graham();
    solve();
    printf("%.2lf",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值