博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P3187 [HNOI2007]最小矩形覆盖
阅读量:6905 次
发布时间:2019-06-27

本文共 1865 字,大约阅读时间需要 6 分钟。

首先这个矩形的一条边肯定在凸包上。那么可以求出凸包然后枚举边,用类似旋转卡壳的方法求出另外三条边的位置,也就是求出以它为底最上面最右边最左边的点的位置。离它最远的点可以用叉积求,最左最右的可以用点积求。顺便注意精度问题,因为很小的时候可能会输出-0.00000,所以特判一下,当坐标小于eps的时候强制它等于0就行了

//minamoto#include
#define fp(i,a,b) for(register int i=a,I=b+1;i
I;--i)#define ab(a) (a<0?a=-a:0)using namespace std;const int N=1e5+5;const double eps=1e-8;struct node{double x,y;}p[N],st[N],q[5];int top,n;inline node operator -(node a,node b){return node{a.x-b.x,a.y-b.y};}inline node operator +(node a,node b){return node{a.x+b.x,a.y+b.y};}inline node operator *(node a,double b){return node{a.x*b,a.y*b};}inline double operator *(node a,node b){return a.x*b.y-b.x*a.y;}inline double dot(node a,node b){return a.x*b.x+a.y*b.y;}inline double area(node a,node b,node c){return fabs((b-a)*(c-a));}inline double len(node a){return sqrt(a.x*a.x+a.y*a.y);}inline bool operator <(node a,node b){ a=a-p[1],b=b-p[1]; return a*b==0?len(a)
0;}void graham(){ int k=1; fp(i,1,n){ scanf("%lf%lf",&p[i].x,&p[i].y); if(p[i].y
=0)--top; st[++top]=p[i]; }st[++top]=p[1];// fp(i,0,top)printf("%.2lf %.2lf\n",st[i].x,st[i].y);}void get(){ double ans=1e100;int a=1,b=1,c=1; fp(i,1,top-2){ while((st[a+1]-st[i])*(st[i-1]-st[i])>=(st[a]-st[i])*(st[i-1]-st[i]))a=(a+1)%top; while(dot(st[b+1]-st[i],st[i-1]-st[i])<=dot(st[b]-st[i],st[i-1]-st[i]))b=(b+1)%top; if(i==1)c=a; while(dot(st[c+1]-st[i-1],st[i]-st[i-1])<=dot(st[c]-st[i-1],st[i]-st[i-1]))c=(c+1)%top; double dis=len(st[i]-st[i-1]); double L=dot(st[c]-st[i],st[i-1]-st[i])/dis;ab(L); double R=dot(st[b]-st[i-1],st[i]-st[i-1])/dis;ab(R); double H=area(st[i],st[i-1],st[a])/dis;ab(H); double tmp=(L+R-dis)*H; if(tmp

转载于:https://www.cnblogs.com/bztMinamoto/p/10009640.html

你可能感兴趣的文章
RTP协议 Q&A
查看>>
linux下php调用root权限实现方案
查看>>
5.Spring Cloud初相识-------Hystrix熔断器
查看>>
CSS3设置Table奇数行和偶数行样式
查看>>
PHP版本过狗Shell
查看>>
BZOJ 2127 happiness ——网络流
查看>>
N皇后问题
查看>>
JavaScript检测数据类型
查看>>
观察者模式
查看>>
《CLR via C#》读书笔记 之 类型基础
查看>>
EXt js 学习笔记总结
查看>>
Vue---父子组件之间的通信
查看>>
第八章:手工建库
查看>>
JavaScript语法
查看>>
js事件浏览器兼容
查看>>
获取贴吧对应页html及写入文件
查看>>
Entity Framework学习初级篇3--LINQ TO Entities
查看>>
android 相对布局
查看>>
SilverLight商业应用程序开发---学习笔记(9)
查看>>
MS DTC 无法正确处理DC升级/降级事件。MS DTC 将继续运行并使用现有的安全设置。...
查看>>