bzoj1185: [HNOI2007]最小矩形覆盖 计算几何 旋转卡壳
来源:互联网 发布:网络计划图软件 编辑:程序博客网 时间:2024/05/21 17:39
又被卡精度。。。这概率绝了!!!
我们可以肯定凸包的一边肯定在矩形上,所以我们直接寻找上,左,右三个顶点就可以了。
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <cmath>using namespace std;#define eps 1e-10#define maxn 51000struct node{ double x,y;}p[maxn],rec[10];double ans=1000000000000;int n;double sqr(double x){ return x*x;}double dis(node a,node b){ return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}node operator -(node a,node b){ node t; t.x=a.x-b.x;t.y=a.y-b.y; return t;}node operator +(node a,node b){ node t; t.x=a.x+b.x;t.y=a.y+b.y; return t;}double operator *(node a,node b){ return a.x*b.y-a.y*b.x;}bool operator <(node a,node b){ if(fabs(a.y-b.y)<eps) return a.x<b.x; return a.y<b.y;}bool cmp(node a,node b){ double t=(a-p[1])*(b-p[1]); if(fabs(t)<=eps) return dis(a,p[1])<dis(b,p[1]); return t>0;}node operator*(node a,double b){ node tmp;tmp.x=a.x*b;tmp.y=a.y*b; return tmp;}double operator/(node a,node b){ return a.x*b.x+a.y*b.y;}node s[maxn];int top;void graham(){ for(int i=2;i<=n;i++) if(p[i]<p[1])swap(p[i],p[1]); sort(p+2,p+n+1,cmp); s[1]=p[1];s[2]=p[2];top=2; for(int i=3;i<=n;i++) { for(;top>1 && (s[top]-s[top-1])*(p[i]-s[top-1])<=0;top--); top++;s[top]=p[i]; } s[top+1]=p[1]; //printf("%d\n",top);}double get(int a,int b,int c){ double tmp=(s[a]-s[b])*(s[a]-s[c]); return fabs(tmp);}double check(int a,int b,int c){ return (s[a]-s[b])/(s[c]-s[b]);}void rc(){ int l=1,r=1,m=1; double L,R,D,H; for(int i=1;i<=top;i++) { D=dis(s[i],s[i+1]); while(get(m+1,i,i+1)-get(m,i,i+1)>-eps ) m=m%top+1; while(check(r+1,i,i+1)-check(r,i,i+1)>-eps) r=r%top+1; if(i==1) l=r; while(check(l+1,i+1,i)-check(l,i+1,i)>-eps) l=l%top+1; L=(s[i+1]-s[i])/(s[l]-s[i])/D; R=(s[i+1]-s[i])/(s[r]-s[i])/D;H=fabs( (s[i+1]-s[i])*(s[m]-s[i])/D );double tmp=(R-L)*H;if(tmp<ans){ ans=tmp;rec[0]=s[i]+(s[i+1]-s[i])*(R/D);rec[1]=rec[0]+(s[r]-rec[0])*(H/dis(rec[0],s[r]));rec[2]=rec[1]-(rec[0]-s[i])*((R-L)/dis(s[i],rec[0]));rec[3]=rec[2]-(rec[1]-rec[0]);} }}int main(){ scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);graham();rc();printf("%.5lf\n",ans);int tmp=0;for(int i=1;i<=3;i++)if(rec[i]<rec[tmp])tmp=i;for(int i=0;i<=3;i++)printf("%.5lf %.5lf\n",rec[(i+tmp)%4].x,rec[(i+tmp)%4].y); return 0;}/*61 31 42 13 03 66 3*/
0 0
- bzoj1185: [HNOI2007]最小矩形覆盖 计算几何 旋转卡壳
- 【BZOJ1185】最小矩形覆盖 计算几何 凸包 旋转卡壳
- BZOJ1185 [HNOI2007]最小矩形覆盖(旋转卡壳)
- [BZOJ1185][HNOI2007]最小矩形覆盖(凸包+旋转卡壳)
- [BZOJ1185][HNOI2007]最小矩形覆盖(旋转卡壳)
- bzoj1185[HNOI2007]最小矩形覆盖
- bzoj1185【HNOI2007】最小矩形覆盖
- 【HNOI2007】bzoj1185 最小矩形覆盖
- BZOJ 1185([HNOI2007]最小矩形覆盖-旋转卡壳+点集几何意义)
- BZOJ 1185 HNOI2007 最小矩形覆盖 旋转卡壳
- BZOJ 1185 [HNOI2007]最小矩形覆盖 旋转卡壳
- bzoj 1185: [HNOI2007]最小矩形覆盖 旋转卡壳
- bzoj 1185: [HNOI2007]最小矩形覆盖 (旋转卡壳)
- 【BZOJ 1185】[HNOI2007]最小矩形覆盖 旋转卡壳
- HDU 5251 矩形面积 (计算几何+旋转卡壳求覆盖凸包的最小矩形面积)
- [旋转卡壳] BZOJ 1185 [HNOI2007]最小矩形覆盖 && 2218 Uva10173 Smallest Bounding Rectangle
- <模板><计算几何>凸包-旋转卡壳最小面积外接矩形
- 1185: [HNOI2007]最小矩形覆盖
- php下memcache的应用(六)——memcache的简单应用
- MySQL各版本介绍
- UITableView的多选删除和滑动删除并存
- Docker源码分析(二):Docker Client创建与命令执行
- Java前辈:学习J2EE流程中的经验和教训
- bzoj1185: [HNOI2007]最小矩形覆盖 计算几何 旋转卡壳
- 关于Java的泛型在所声明的对象中如何获取class或者实例的方法的总结
- 【设计模式】策略模式
- enum 枚举类型 选择输出
- rdesktop架构解析(RDP协议分析)
- linux 用户管理(3)----查看用户登录时间以及命令历史
- 人工智能的冬天【杨强】
- 浏览器内核的解析和对比
- CentOS6.4-x86_64搭建cobbler+kickstart的网络无盘启动服务器