传送门: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;
}