信用卡凸包(凸包)

#include<bits/stdc++.h>
#define x first 
#define y second
using namespace std;

typedef pair<double,double> pdd;
const int N=40010;
const double pi=acos(-1);
int n,cnt;
pdd q[N];
int stk[N],top;
bool used[N];

pdd rotate(pdd a,double b){
	return {a.x*cos(b)+a.y*sin(b),-a.x*sin(b)+a.y*cos(b)};
}

pdd operator-(pdd a,pdd b){
	return {a.x-b.x,a.y-b.y};
}
double cross(pdd a,pdd b){
	return a.x*b.y-a.y*b.x;
} 
double area(pdd a,pdd b,pdd c){
	return cross(b-a,c-a);
}
double get_dist(pdd a,pdd b){
	double dx=a.x-b.x;
	double dy=a.y-b.y;
	return sqrt(dx*dx+dy*dy);
}
double solve(){
	sort(q,q+cnt);
	for(int i=0;i<cnt;i++){
		while(top>=2&&area(q[stk[top-1]],q[stk[top]],q[i])>0)
			used[stk[top--]]=false;
		stk[++top]=i;
		used[i]=true;
	}
	used[0]=false;
	for(int i=cnt-1;i>=0;i--){
		if(used[i]) continue;
		while(top>=2&&area(q[stk[top-1]],q[stk[top]],q[i])>0)
			top--;
		stk[++top]=i;
	}
	double ans=0;
	for(int i=2;i<=top;i++){
		ans+=get_dist(q[stk[i-1]],q[stk[i]]);
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	double a,b,r;
	scanf("%lf%lf%lf",&a,&b,&r);
	a=a/2-r,b=b/2-r;
	int dx[]={1,1,-1,-1},dy[]={1,-1,1,-1};
	while(n--){
		double x,y,z;
		scanf("%lf%lf%lf",&x,&y,&z);
		for(int i=0;i<4;i++){
			pdd t=rotate({dx[i]*b,dy[i]*a},-z);
			q[cnt++]={x+t.x,y+t.y};
		}
	}
	double ans=solve();
	printf("%.2lf\n",ans+2*pi*r);
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值