[BZOJ2829] 信用卡 (凸包)
[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] 信用卡 (凸包)的更多相关文章
- BZOJ2829信用卡凸包——凸包
题目描述 输入 输出 样例输入 2 6.0 2.0 0.0 0.0 0.0 0.0 2.0 -2.0 1.5707963268 样例输出 21.66 提示 本样例中的2张信用卡的轮廓在上图中用实线标出 ...
- Bzoj2829 信用卡凸包
Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 333 Solved: 155 Description Input ...
- BZOJ-2829 信用卡凸包
凸包题. 我们先把所有信用卡的四个定点的坐标求出来,然后计算凸包长度,最后加上一个圆的周长就行. #include <cstdlib> #include <cstdio> #i ...
- 2019.02.21 bzoj2829: 信用卡凸包(凸包)
传送门 题意:给nnn个A∗BA*BA∗B的矩形,其中每个矩形的四个角被改造成了半径为rrr的四分之一 圆,问这些矩形的凸包周长. 思路:考虑求出圆心的凸包周长然后加上一个整圆的周长,证明很简单,略掉 ...
- 【计算几何】【凸包】bzoj2829 信用卡凸包
http://hzwer.com/6330.html #include<cstdio> #include<cmath> #include<algorithm> us ...
- 【BZOJ2829】[SHOI2012]信用卡凸包(凸包)
[BZOJ2829][SHOI2012]信用卡凸包(凸包) 题面 BZOJ 洛谷 题解 既然圆角的半径都是一样的,而凸包的内角和恰好为\(360°\),所以只需要把圆角的圆心弄下来跑一个凸包,再额外加 ...
- 【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 ...
- bzoj 2829 信用卡凸包(凸包)
2829: 信用卡凸包 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1342 Solved: 577 [Submit][Status][Disc ...
- [SHOI2012]信用卡凸包(凸包+直觉)
这个题还是比较有趣. 小心发现,大胆猜想,不用证明! 我们发现所谓的信用卡凸包上弧的长度总和就是圆的周长! 然后再加上每个长宽都减去圆的直径之后的长方形的凸包周长即可! #include<ios ...
随机推荐
- windows 安装php
php各个版本下载地址:https://www.apachelounge.com/viewtopic.php?t=6359 https://museum.php.net/ https://www.fu ...
- Linux为程序员添加了行为准则
假如你是开发人员,如果您密切关注Linux开发,您就会知道Linux内核讨论会非常热烈.最近,LinusTorvalds承认Linux内核邮件列表(LKML)和其他Linux开发空间对许多人都是敌对的 ...
- AGC009题解
为了1天4题的flag不倒所以开新坑... B. 考虑把这棵树直接建出来,f[i]表示i最少的比赛次数,然后按照定义转移就行了. //Love and Freedom. #include<cst ...
- hihocode 1584 : Bounce (找规律)(2017 北京网络赛G)
题目链接 比赛时随便找了个规律,然后队友过了.不过那个规律具体细节还挺烦的.刚刚偶然看到Q巨在群里提到的他的一个思路,妙啊,很好理解,而且公式写起来也容易.OrzQ巨 #include<bits ...
- 自动配置/切换/查看JDK环境变量
最近老是需要几个版本的JDK切换工作,于是网上收集资料整理,自己写了一个:自动配置/切换/查看JDK环境变量的批处理脚本.顺带3个JDK版本分别是:jdk1.6.0_43,jdk1.7.0_80,jd ...
- mysql INSERT语句 语法
mysql INSERT语句 语法 作用:用于向表格中插入新的行. 语法:INSERT INTO 表名称 VALUES (值1, 值2,....)或者INSERT INTO table_name (列 ...
- makefile filter &&filter-out
sources := foo.c bar.c baz.s abc.h foo: $(sources) gcc $(filter %.c %.s,$(sources)) -o ...
- Java——常用类(Math)
[常用方法] 这些方法为静态方法.
- Hello Kotlin! Kotlin学习资料
今天谷歌搞了条大新闻.宣布Kotlin成为android开发的一级(One Class)语言,这说明谷歌是被甲骨文恶心坏了,打算一步步脱离掉java或者说是甲骨文公司的束缚了.原先网上大家还琢磨着会不 ...
- SpringMVC常用方法总结
*) @RequestMapping(value="/xxx/{id}",method={RequestMethod.GET}) method 不写的话,默认GET.POST都支持 ...