P3829 [SHOI2012]信用卡凸包

传送门

不难发现这个信用卡凸包的周长就是一个整圆的周长再加上所有的四个边角的点形成的凸包

于是直接把这个凸包求出来即可

还有就是一个向量((x,y))逆时针旋转(t)度之后坐标是((x*cos(t)-y*sin(t),x*sin(t)+y*cos(t)))(话说原来这玩意儿还有公式的么……)

//minamoto
#include<bits/stdc++.h>
#define inf 1e10
#define eps 1e-10
#define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
using namespace std;
const int N=1e5+5;const double Pi=acos(-1.0);
struct node{
	double x,y;
	node(double X=0,double Y=0):x(X),y(Y){}
	inline node operator +(const node &b)const
	{return node(x+b.x,y+b.y);}
}p[N],st[N],rs;
int n,k,top,tot;double ans,a,b,r,x,y,t;
inline bool cmp(node a,node b){
	double A=atan2(a.y-p[1].y,a.x-p[1].x);
	double B=atan2(b.y-p[1].y,b.x-p[1].x);
	return A!=B?A<B:a.x<b.x;
}
inline double cross(node a,node b,node c){return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}
inline double dis(node a,node b){return sqrt((b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x));}
inline node rotate(node a,double t){
	double s=sin(t),c=cos(t);
	return node(a.x*c-a.y*s,a.x*s+a.y*c);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%lf%lf%lf",&n,&b,&a,&r),p[0]=node(inf,inf);
	a/=2.0,b/=2.0;
	fp(i,1,n){
		scanf("%lf%lf%lf",&x,&y,&t),rs=node(x,y);
		p[++tot]=rotate(node(a-r,b-r),t)+rs;
		p[++tot]=rotate(node(r-a,b-r),t)+rs;
		p[++tot]=rotate(node(a-r,r-b),t)+rs;
		p[++tot]=rotate(node(r-a,r-b),t)+rs;
	}
	fp(i,1,tot)if(p[0].y>p[i].y||(p[0].y==p[i].y&&p[0].x>p[i].x))p[0]=p[i],k=i;
	swap(p[k],p[1]),sort(p+2,p+1+tot,cmp);
	st[0]=p[1],st[1]=p[2],top=1;
	fp(i,3,tot){
		while(top&&cross(st[top-1],p[i],st[top])>=0)--top;
		st[++top]=p[i];
	}
	ans=2*Pi*r,st[++top]=st[0];
	fp(i,1,top)ans+=dis(st[i],st[i-1]);
	printf("%.2lf
",ans);return 0;
}
原文地址:https://www.cnblogs.com/bztMinamoto/p/10000517.html