【BZOJ 2829】信用卡凸包 凸包

8 篇文章 0 订阅
3 篇文章 0 订阅

求一个凸包然后加上一个圆就没有了,主要是联系一下模板(我的主要是用的lrj的大白上面的)。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define maxn 100005
using namespace std;
int n,cnt;
double r,len,wide,ans;
const double eps=1e-7;
struct P{
	double x,y;
	P(double a=0,double b=0):x(a),y(b){}
}q[maxn],p[maxn];
struct node{
	double x,y,angle;
}dia[maxn];
typedef P Vec;
Vec operator + (Vec a,Vec b){return Vec(a.x+b.x,a.y+b.y);}
Vec operator - (P a,P b){return Vec(a.x-b.x,a.y-b.y);}
Vec operator * (Vec a,double p){return Vec(a.x*p,a.y*p);}
Vec operator / (Vec a,double p){return Vec(a.x/p,a.y/p);}
double cross(Vec a,Vec b){return a.x*b.y-a.y*b.x;}
bool operator < (const P& a,const P& b){
	return a.x==b.x ? a.y<b.y : a.x<b.x;
}
double sqr(double x){return x*x;}
double dis2(Vec a){return sqr(a.x)+sqr(a.y);}
P move(P a,double d,double rad){
	return P(a.x+d*cos(rad),a.y+d*sin(rad));
}
void build(){
	for(int i=1;i<=n;i++){
		for(int k=0;k<4;k++){
			P t=move(P(dia[i].x,dia[i].y),len/2,dia[i].angle+k*M_PI/2);
			p[++cnt]=move(t,wide/2,dia[i].angle+(k+1)*M_PI/2);
			swap(wide,len);
		}
	}
}
//左正右负 
void ConvexHull(){
	sort(p+1,p+1+cnt);
	int top=0;
	for(int i=1;i<=cnt;i++){
		while(top>1&&cross(q[top]-q[top-1],p[i]-q[top-1])<=0)top--;
		q[++top]=p[i];
	}int m=top;
	for(int i=cnt-1;i>=1;i--){
		while(top>m&&cross(q[top]-q[top-1],p[i]-q[top-1])<=0)top--;
		q[++top]=p[i];
	}
	for(int i=2;i<=top;i++){
		ans+=sqrt(dis2(q[i]-q[i-1]));
	}
	printf("%.2lf",ans);
}
int main(){
	scanf("%d",&n);
	scanf("%lf%lf%lf",&wide,&len,&r);
	wide-=2.0*r,len-=2.0*r;
	ans+=2*M_PI*r;
	for(int i=1;i<=n;i++){
		scanf("%lf%lf%lf",&dia[i].x,&dia[i].y,&dia[i].angle);
	}
	build();
	ConvexHull();
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值