求一个凸包然后加上一个圆就没有了,主要是联系一下模板(我的主要是用的lrj的大白上面的)。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define maxn 100005
using namespace std;
int n,cnt;
double r,len,wide,ans;
const double eps=1e-7;
struct P{
double x,y;
P(double a=0,double b=0):x(a),y(b){}
}q[maxn],p[maxn];
struct node{
double x,y,angle;
}dia[maxn];
typedef P Vec;
Vec operator + (Vec a,Vec b){return Vec(a.x+b.x,a.y+b.y);}
Vec operator - (P a,P b){return Vec(a.x-b.x,a.y-b.y);}
Vec operator * (Vec a,double p){return Vec(a.x*p,a.y*p);}
Vec operator / (Vec a,double p){return Vec(a.x/p,a.y/p);}
double cross(Vec a,Vec b){return a.x*b.y-a.y*b.x;}
bool operator < (const P& a,const P& b){
return a.x==b.x ? a.y<b.y : a.x<b.x;
}
double sqr(double x){return x*x;}
double dis2(Vec a){return sqr(a.x)+sqr(a.y);}
P move(P a,double d,double rad){
return P(a.x+d*cos(rad),a.y+d*sin(rad));
}
void build(){
for(int i=1;i<=n;i++){
for(int k=0;k<4;k++){
P t=move(P(dia[i].x,dia[i].y),len/2,dia[i].angle+k*M_PI/2);
p[++cnt]=move(t,wide/2,dia[i].angle+(k+1)*M_PI/2);
swap(wide,len);
}
}
}
//左正右负
void ConvexHull(){
sort(p+1,p+1+cnt);
int top=0;
for(int i=1;i<=cnt;i++){
while(top>1&&cross(q[top]-q[top-1],p[i]-q[top-1])<=0)top--;
q[++top]=p[i];
}int m=top;
for(int i=cnt-1;i>=1;i--){
while(top>m&&cross(q[top]-q[top-1],p[i]-q[top-1])<=0)top--;
q[++top]=p[i];
}
for(int i=2;i<=top;i++){
ans+=sqrt(dis2(q[i]-q[i-1]));
}
printf("%.2lf",ans);
}
int main(){
scanf("%d",&n);
scanf("%lf%lf%lf",&wide,&len,&r);
wide-=2.0*r,len-=2.0*r;
ans+=2*M_PI*r;
for(int i=1;i<=n;i++){
scanf("%lf%lf%lf",&dia[i].x,&dia[i].y,&dia[i].angle);
}
build();
ConvexHull();
return 0;
}