[BZOJ2829] 信用卡 (凸包)

题面

信用卡是一个矩形,唯四个角做了圆滑处理,使他们都是与矩形两边相切的1/4园,如下图所示,现在平面上有一些规格相同的信用卡,试求其凸包的周长。注意凸包未必是多边形,因为他有可能包含若干段圆弧。

分析

我们发现凸包的圆弧段可以缩成一个圆,然后将直线段向内平移,就可以组成一个多边形

因此对每个卡的四个圆心跑凸包,答案为凸包周长+一个圆的周长

注意四个圆心的计算要用到向量旋转,向量\((x,y)\)逆时针旋转\(\alpha\)(弧度)之后会变成\((x\cos \alpha-y \sin \alpha,x \sin \alpha+y \cos \alpha)\)

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define eps 1e-6
#define maxn 10000
using namespace std;
int n;
const double PI=acos(-1.0);
struct Vector{
double x;
double y;
Vector(){ }
Vector(double _x,double _y){
x=_x;
y=_y;
}
friend Vector operator + (Vector p,Vector q){
return Vector(p.x+q.x,p.y+q.y);
}
friend Vector operator - (Vector p,Vector q){
return Vector(p.x-q.x,p.y-q.y);
}
friend bool operator < (Vector p,Vector q){
if(p.x==q.x) return p.y<q.y;
else return p.x<q.x;
}
};
typedef Vector point;
inline double dot(Vector p,Vector q){
return p.x*q.x+p.y*q.y;
}
inline double dist(point p,point q){
return sqrt(dot(p-q,p-q));
}
inline double cross(Vector p,Vector q){
return p.x*q.y-p.y*q.x;
}
Vector rotate(Vector a,double theta){
return Vector(a.x*cos(theta)-a.y*sin(theta),a.x*sin(theta)+a.y*cos(theta));
} double a,b,r;
int cnt=0;
point p[maxn*4+5];
int top=0;
point s[maxn*4+5];
int cmp(point x,point y){
double ang=cross(x-p[1],y-p[1]);
if(fabs(ang)<eps) return dist(p[1],x)<dist(p[1],y);
else return ang>eps;
} int main(){
double x,y,theta;
Vector d[5];
scanf("%d",&n);
scanf("%lf %lf %lf",&a,&b,&r);
a-=2*r;
b-=2*r;
d[1]=Vector(-b/2,a/2);
d[2]=Vector(-b/2,-a/2);
d[3]=Vector(b/2,a/2);
d[4]=Vector(b/2,-a/2);
for(int i=1;i<=n;i++){
scanf("%lf %lf %lf",&x,&y,&theta);
for(int j=1;j<=4;j++){
p[++cnt]=point(x,y)+rotate(d[j],theta);
}
}
#ifdef DEBUG
printf("%d\n",cnt);
for(int i=1;i<=cnt;i++){
printf("(%.2f,%.2f)\n",p[i].x,p[i].y);
}
#endif
for(int i=1;i<=cnt;i++){
if(p[i]<p[1]) swap(p[1],p[i]);
}
sort(p+2,p+1+cnt,cmp);
for(int i=1;i<=cnt;i++){
while(top>1&&cross(s[top]-s[top-1],p[i]-s[top-1])<=eps) top--;
s[++top]=p[i];
}
double ans=0;
for(int i=1;i<top;i++) ans+=dist(s[i],s[i+1]);
ans+=dist(s[top],s[1]);
ans+=2*PI*r;
printf("%.2lf\n",ans);
}

[BZOJ2829] 信用卡 (凸包)的更多相关文章

  1. BZOJ2829信用卡凸包——凸包

    题目描述 输入 输出 样例输入 2 6.0 2.0 0.0 0.0 0.0 0.0 2.0 -2.0 1.5707963268 样例输出 21.66 提示 本样例中的2张信用卡的轮廓在上图中用实线标出 ...

  2. Bzoj2829 信用卡凸包

    Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 333  Solved: 155 Description Input ...

  3. BZOJ-2829 信用卡凸包

    凸包题. 我们先把所有信用卡的四个定点的坐标求出来,然后计算凸包长度,最后加上一个圆的周长就行. #include <cstdlib> #include <cstdio> #i ...

  4. 2019.02.21 bzoj2829: 信用卡凸包(凸包)

    传送门 题意:给nnn个A∗BA*BA∗B的矩形,其中每个矩形的四个角被改造成了半径为rrr的四分之一 圆,问这些矩形的凸包周长. 思路:考虑求出圆心的凸包周长然后加上一个整圆的周长,证明很简单,略掉 ...

  5. 【计算几何】【凸包】bzoj2829 信用卡凸包

    http://hzwer.com/6330.html #include<cstdio> #include<cmath> #include<algorithm> us ...

  6. 【BZOJ2829】[SHOI2012]信用卡凸包(凸包)

    [BZOJ2829][SHOI2012]信用卡凸包(凸包) 题面 BZOJ 洛谷 题解 既然圆角的半径都是一样的,而凸包的内角和恰好为\(360°\),所以只需要把圆角的圆心弄下来跑一个凸包,再额外加 ...

  7. 【BZOJ 2829】 2829: 信用卡凸包 (凸包)

    2829: 信用卡凸包 Description Input Output Sample Input 2 6.0 2.0 0.0 0.0 0.0 0.0 2.0 -2.0 1.5707963268 Sa ...

  8. bzoj 2829 信用卡凸包(凸包)

    2829: 信用卡凸包 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 1342  Solved: 577 [Submit][Status][Disc ...

  9. [SHOI2012]信用卡凸包(凸包+直觉)

    这个题还是比较有趣. 小心发现,大胆猜想,不用证明! 我们发现所谓的信用卡凸包上弧的长度总和就是圆的周长! 然后再加上每个长宽都减去圆的直径之后的长方形的凸包周长即可! #include<ios ...

随机推荐

  1. jquery编写插件(转)

    教你开发jQuery插件(转)   阅读目录 基本方法 支持链式调用 让插件接收参数 面向对象的插件开发 关于命名空间 关于变量定义及命名 压缩的好处 工具 GitHub Service Hook 原 ...

  2. B1016. 部分 A+B

    题目描述 正整数A的"D(为1位整数)部分"定义由A中所有D组成的新整数P,例如给定A=3862767,D=6,则A的"6部分" P是66,因为A中有2个6,现 ...

  3. Java 8 Date常用工具类

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11983108.html Demo package org.fool.util; import java ...

  4. Math.min() Math.max() Math.min().apply() Math.max() .apply()该如何使用???

    Math.min()和 Math.max()  语法: Math.min(x,y) Math.max(x,y) 虽然能取到最小值和最大值,但是不支持数组. 那么如何计算数组中的大小值呢???????? ...

  5. POJ 3280 Cheapest Palindrome ( 区间DP && 经典模型 )

    题意 : 给出一个由 n 中字母组成的长度为 m 的串,给出 n 种字母添加和删除花费的代价,求让给出的串变成回文串的代价. 分析 :  原始模型 ==> 题意和本题差不多,有添和删但是并无代价 ...

  6. POJ 3061 Subsequence ( 二分 || 尺取法 )

    题意 : 找出给定序列长度最小的子序列,子序列的和要求满足大于或者等于 S,如果存在则输出最小长度.否则输出 0(序列的元素都是大于 0 小于10000) 分析 : 有关子序列和的问题,都可以考虑采用 ...

  7. Manacher模板( 线性求最长回文子串 )

    模板 #include<stdio.h> #include<string.h> #include<algorithm> #include<map> us ...

  8. es的索引库模板

    在实际的生产中,如果要插入大批量数据的时候需要使用多个索引库,如果我们还是手工指定每个索引的配置信息settings和mappings,是非常耗时的: 针对这种情况,es有index template ...

  9. uva live 7637 Balanced String (贪心)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  10. JavaScript code modules

    https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules Non-standardThis feature is ...