凸包求调
  • 板块灌水区
  • 楼主zhx20081129
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/1 10:33
  • 上次更新2024/8/1 11:22:27
查看原帖
凸包求调
914572
zhx20081129楼主2024/8/1 10:33

https://www.luogu.com.cn/problem/P3829

P3829 [SHOI2012] 信用卡凸包

样例不过,实在看不出来哪错了

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+7;
int n,cnt,tot;
double a,b,r;
struct T{
	double x,y;
}p[N],s[N];
double check(T A, T B,T C,T D){
	return (B.x-A.x)*(D.y-C.y)-(D.x-C.x)*(B.y-A.y);
}
double d(T A,T B){
	return sqrt((B.y-A.y)*(B.y-A.y)+(B.x-A.x)*(B.x-A.x));
}
bool cmp(T A,T B){
	double tmp=check(A,p[1],B,p[1]);
	if(tmp>0)return 1;
	else if(tmp==0&&d(p[0],A)<d(p[0],B))return 1;
	return 0;
}
void add(double x,double y){
	p[++tot]={x,y};
	if(p[tot].y<p[1].y)swap(p[tot],p[1]);
}
void work(){
	sort(p+2,p+n+1,cmp);
	s[1]=p[1];cnt=1;
	for(int i=2;i<=n;i++){
		while(cnt>1&&check(s[cnt-1],s[cnt],s[cnt],p[i])<=0)cnt--;
		s[++cnt]=p[i];
	}
	s[cnt+1]=p[1];
} 
double calc(){
	double ans=0;
	for(int i=1;i<=cnt;i++){
		ans+=d(s[i],s[i+1]);
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>a>>b>>r;
	a-=2*r,b-=2*r;
	double l=sqrt(a*a+b*b)/2;
	double phi=atan(a/b);
	for(int i=1;i<=n;i++){
		double x,y,th;
		cin>>x>>y>>th;
		double dx=cos(th+phi)*l,dy=sin(th+phi)*l;
		add(x+dx,y+dy);add(x-dx,y-dy);
		dx=cos(th-phi)*l,dy=sin(th-phi)*l;
		add(x+dx,y+dy);add(x-dx,y-dy);
	}	
	work();
	cout<<fixed<<setprecision(2)<<calc()+3.141592653589793*2*r;
	return 0;
}
2024/8/1 10:33
加载中...