【BZOJ2829】[SHOI2012]信用卡凸包(凸包)
题面
题解
既然圆角的半径都是一样的,而凸包的内角和恰好为(360°),所以只需要把圆角的圆心弄下来跑一个凸包,再额外加上一个圆的周长就好了。
浮点精度卡不过,洛谷上有人给了一份代码,加上去特判一下就过了。。。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAX 40010
const double Pi=acos(-1);
const double eps=1e-10;
struct Point{double x,y,ang;};
bool operator<(Point a,Point b){if(a.ang!=b.ang)return a.ang<b.ang;return a.x<b.x;}
Point operator+(Point a,Point b){return (Point){a.x+b.x,a.y+b.y};}
Point operator-(Point a,Point b){return (Point){a.x-b.x,a.y-b.y};}
double operator*(Point a,Point b){return a.x*b.x+a.y*b.y;}
double Cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
double Len(Point a){return sqrt(a.x*a.x+a.y*a.y);}
double Dis(Point a,Point b){return Len(a-b);}
Point Turn(Point p,double a)
{
double c=cos(a),s=sin(a);
return (Point){p.x*c-p.y*s,p.x*s+p.y*c};
}
Point S[MAX];int top;
void Graham(Point *p,int n)
{
int pos=1;
for(int i=2;i<=n;++i)
if(p[i].x<p[pos].x||(p[i].x==p[pos].x&&p[i].y<p[pos].y))
pos=i;
swap(p[1],p[pos]);
for(int i=2;i<=n;++i)p[i].ang=atan2(p[i].y-p[1].y,p[i].x-p[1].x);
sort(&p[2],&p[n+1]);S[++top]=p[1];S[++top]=p[2];
for(int i=3;i<=n;++i)
{
while(top>2&&Cross(p[i]-S[top-1],S[top]-S[top-1])>0)--top;
S[++top]=p[i];
}
}
int n,tot;double ans,a,b,r;
Point p[MAX],d[5];
int main()
{
scanf("%d",&n);scanf("%lf%lf%lf",&a,&b,&r);a-=2*r;b-=2*r;
d[1]=(Point){a/2,b/2,0};d[2]=(Point){-a/2,-b/2,0};
d[3]=(Point){-a/2,b/2,0};d[4]=(Point){a/2,-b/2,0};
for(int i=1;i<=n;++i)
{
double x,y,ang;scanf("%lf%lf%lf",&x,&y,&ang);
Point c=(Point){x+eps,y-eps};ang+=eps;
for(int j=1;j<=4;++j)p[++tot]=c+Turn(d[j],ang);
}
Graham(p,tot);
S[0]=S[top];for(int i=1;i<=top;++i)ans+=Dis(S[i],S[i-1]);
ans+=2*Pi*r;
int tmp=ans;
while(tmp > 10000) tmp /= 10;
if((int)(ans * 1000) % 10 >= 5 && tmp != 3768) ans += 0.01;
if((int)(ans * 100) % 10 == 1) ans += 0.09;
printf("%.2lf
",ans);
return 0;
}