[SHOI2012]信用卡凸包(凸包+直觉)
2024-08-31 08:23:15
这个题还是比较有趣。
小心发现,大胆猜想,不用证明!
我们发现所谓的信用卡凸包上弧的长度总和就是圆的周长!
然后再加上每个长宽都减去圆的直径之后的长方形的凸包周长即可!
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=40100;
const double eps=1e-12;
int stack[N],top,n;
double a,b,r,ans;
struct node{
double x,y;
node(double xx=0,double yy=0){
x=xx;y=yy;
}
}c[N];
node work(node a,double x){
double A=cos(x),B=sin(x);
return node(a.x*A-a.y*B,a.x*B+a.y*A);
}
bool cmp(node a,node b){
if(a.x==b.x)return a.y<b.y;
else return a.x<b.x;
}
double chaji(node a,node b){
return a.x*b.y-a.y*b.x;
}
node operator -(node a,node b){
return node(a.x-b.x,a.y-b.y);
}
node operator +(node a,node b){
return node(a.x+b.x,a.y+b.y);
}
double dis(node a,node b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main(){
scanf("%d",&n);
scanf("%lf%lf%lf",&a,&b,&r);
a-=2.0*r;b-=2.0*r;
ans=acos(-1.0)*r*2.0;
for(int i=0;i<n;i++){
double x,y,z;
scanf("%lf%lf%lf",&x,&y,&z);
c[i*4+1].x=b/2.0;c[i*4+1].y=a/2.0;
c[i*4+1]=work(c[i*4+1],z);c[i*4+1].x+=x;c[i*4+1].y+=y;
c[i*4+2].x=-b/2.0;c[i*4+2].y=a/2.0;
c[i*4+2]=work(c[i*4+2],z);c[i*4+2].x+=x;c[i*4+2].y+=y;
c[i*4+3].x=b/2.0;c[i*4+3].y=-a/2.0;
c[i*4+3]=work(c[i*4+3],z);c[i*4+3].x+=x;c[i*4+3].y+=y;
c[i*4+4].x=-b/2.0;c[i*4+4].y=-a/2.0;
c[i*4+4]=work(c[i*4+4],z);c[i*4+4].x+=x;c[i*4+4].y+=y;
}
sort(c+1,c+1+n*4,cmp);
for(int i=1;i<=n*4;i++){
if(top<=1){stack[++top]=i;continue;}
while(top>=2&&chaji(c[stack[top]]-c[stack[top-1]],c[i]-c[stack[top]])+eps<0)top--;
stack[++top]=i;
}
for(int i=1;i<top;i++)ans+=dis(c[stack[i]],c[stack[i+1]]);
top=0;
for(int i=n*4;i>=1;i--){
if(top<=1){stack[++top]=i;continue;}
while(top>=2&&chaji(c[stack[top]]-c[stack[top-1]],c[i]-c[stack[top]])+eps<0)top--;
stack[++top]=i;
}
for(int i=1;i<top;i++)ans+=dis(c[stack[i]],c[stack[i+1]]);
printf("%.2lf",ans);
return 0;
}
最新文章
- Unable to create the selected property page. An error occurred while automatically activating bundle net.sourceforge.pmd
- angularjs中的filter(过滤器)——格式化日期的date
- Android 热修复,插件式开发---基本知识
- css的小问题总结
- Postgresql 帐号密码修改方法
- android res文件夹下面的 values-v11 、 values-v14
- 内存恶鬼drawRect
- iOS 获取设备型号以及IP地址
- 深入剖析keil c51 --- 从汇编到c51
- 博弈论(Game Theory) - 01 - 前传之占优战略均衡
- 在tomcat7中启用HTTPS的详细配置
- [LeetCode] Number of Atoms 原子的个数
- ThetaSome_ThetaAll子查询
- 如何添加使用echats地图悬浮显示内容
- maven打包不包含配置文件[z]
- SQL Data Compare 对比 SQLserver数据
- tomcat部署项目(war文件)
- jQuery实用Demo
- tesseract-ocr识别中文扫描图片实例讲解
- SQL 正则表达式 `(user_log_acct)?+.+`