70pts求条
查看原帖
70pts求条
742275
_czy楼主2024/12/10 13:16

求条

#include<bits/stdc++.h>
using namespace std;
#define N 100003
#define db long double
#define pf(x) ((x)*(x))
const int eps=1e-6;
int tx[]={1,1,-1,-1},ty[]={1,-1,1,-1},n,s[N],tp,cnt;
db ans,A,B,R,C,x,y,z;
struct node{
	db x,y;
}a[N];
bool cmp(node x,node y){
	if(x.x==y.x)return x.y<y.y;
	return x.x<y.x;
}
db dis(node x,node y){
	return sqrt(pf(x.x-y.x)+pf(x.y-y.y));
}
db gk(node x,node y){
	if(x.x==y.x)return 1e10;
	return (x.y-y.y)/(x.x-y.x);
}
node rotate(node a, double t){
	db c=cos(t),s=sin(t);
	return {a.x*c-a.y*s,a.x*s+a.y*c};
}
int main(){
	scanf("%d%Lf%Lf%Lf",&n,&A,&B,&R);
	A=A/2,B=B/2;
	for(int i=1;i<=n;i++){
		scanf("%Lf%Lf%Lf",&x,&y,&z);
		a[++cnt]=rotate({A-R,B-R},z);
		a[cnt].x+=x,a[cnt].y+=y;
		a[++cnt]=rotate({R-A,B-R},z);
		a[cnt].x+=x,a[cnt].y+=y;
		a[++cnt]=rotate({R-A,R-B},z);
		a[cnt].x+=x,a[cnt].y+=y;
		a[++cnt]=rotate({A-R,R-B},z);
		a[cnt].x+=x,a[cnt].y+=y;
	}
	n=cnt;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		while(tp>1&&gk(a[s[tp-1]],a[s[tp]])<gk(a[s[tp]],a[i]))tp--;
		s[++tp]=i;
	}
	while(--tp)ans+=dis(a[s[tp]],a[s[tp+1]]);
	for(int i=n;i;i--){
		while(tp>1&&gk(a[s[tp-1]],a[s[tp]])<gk(a[s[tp]],a[i]))tp--;
		s[++tp]=i;
	}
	while(--tp)ans+=dis(a[s[tp]],a[s[tp+1]]);
	printf("%.2Lf",ans+2*acos(-1)*R);
}
2024/12/10 13:16
加载中...