【bzoj2829】【信用卡凸包】【凸包】

Description

Input

Output

Sample Input

2
6.0 2.0 0.0
0.0 0.0 0.0
2.0 -2.0 1.5707963268

Sample Output

21.66

HINT


本样例中的2张信用卡的轮廓在上图中用实线标出,如果视1.5707963268为

Pi/2(pi为圆周率),则其凸包的周长为16+4*sqrt(2)

题解:

           把边上的圆去掉然后求一遍凸包,最后再加上一个圆的周长即可.

           求顶点的时候注意角度问题.

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 100010
#define eps 1e-8
#define pie acos(-1)
using namespace std;
int n,cnt,top;
double ans,a,b,r;
struct use{double x,y;}p[N<<2],st[N<<2];
struct mat{double angle,x,y;}ma[N];
bool operator<(use a,use b){
  if (fabs(a.x-b.x)<eps) return a.y<b.y;
  else return a.x<b.x;
}
double operator*(use a,use b){
  return a.x*b.y-a.y*b.x;
}
use operator-(use a,use b){
  use c;
  c.x=a.x-b.x;
  c.y=a.y-b.y;
  return c;
}
double dis(use a){
  return sqrt(a.x*a.x+a.y*a.y);
}
use rotate(use a,double len,double angle){
  use t;
  t.x=a.x+len*cos(angle);
  t.y=a.y+len*sin(angle);
  return t; 
}
bool judge(use a,use b,use c){
  return (b-a)*(c-a)<-eps;
}
bool cmp(use a,use b){
  if (fabs((a-p[1])*(b-p[1]))<eps) return dis(a-p[1])<dis(b-p[1]);
  else return (a-p[1])*(b-p[1])>0; 
}
void graham(){
  top=0;
  for (int i=1;i<=cnt;i++)
     if (p[i]<p[1]) swap(p[1],p[i]);
  sort(p+2,p+cnt+1,cmp);    
  for (int i=1;i<=cnt;i++){
    while (top>1&&judge(st[top-1],st[top],p[i])) top--;  
    st[++top]=p[i];
  }
}
void getpoint(){
  for (int i=1;i<=n;i++)
    for (int k=0;k<4;k++){
       use t=rotate(use{ma[i].x,ma[i].y},b/2,k*pie/2+ma[i].angle);
       p[++cnt]=rotate(t,a/2,(k+1)*pie/2+ma[i].angle);
       swap(a,b);
    }
}
int main(){
  scanf("%d",&n);
  scanf("%lf%lf%lf",&a,&b,&r);
  a-=2*r;b-=2*r;ans=2*pie*r;
  for (int i=1;i<=n;i++)
    scanf("%lf%lf%lf",&ma[i].x,&ma[i].y,&ma[i].angle);
  getpoint();
  graham();
  st[++top]=st[1];
  for (int i=1;i<=top-1;i++)
    ans+=dis(st[i]-st[i+1]);
  printf("%.2lf\n",ans); 
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值