bzoj 1185
题目大意: 给你n个点求最小矩形覆盖。
思路:枚举凸包上的边然后,旋转卡壳找三个相应的为止把矩形的四个点求出来。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int>> using namespace std; const int N=1e5 + ;
const int M=1e4 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, cnt; int dcmp(double x) {
if(fabs(x) < eps) return ;
else return x < ? - : ;
} struct Point {
double x, y;
Point(double x = , double y = ) : x(x), y(y) { } }p[N], ch[N]; typedef Point Vector; Point operator + (Vector A, Vector B) {return Point(A.x + B.x, A.y + B.y);}
Point operator - (Vector A, Vector B) {return Point(A.x - B.x, A.y - B.y);}
Point operator * (Vector A, double p) {return Point(A.x * p, A.y * p);}
Point operator / (Vector A, double p) {return Point(A.x / p, A.y / p);}
bool operator < (const Vector &A, const Vector &B) {return A.y < B.y || (A.y == B.y && A.x < B.x);}
bool operator == (const Vector &A, const Point &B) {return dcmp(A.x - B.x) == && dcmp(A.y - B.y) == ;}
double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;}
double Length(Vector A) {return sqrt(Dot(A, A));}
double Angle(Vector A, Vector B) {return acos(Dot(A, B) / Length(A) / Length(B));}
double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;}
double Area2(Point A, Point B, Point C) {return Cross(B - A, C - A);} Vector Rotate(Vector A, double rad) {
return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
} Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {
Vector u = P - Q;
double t = Cross(w, u) / Cross(v, w);
return P + v * t;
} double dis(Point A, Point B) {
return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
}
int ConvexHull(Point *p, int n, Point *ch) {
sort(p, p + n);
int m = ;
for(int i = ; i < n; i++) {
while(m > && dcmp(Cross(ch[m - ] - ch[m - ], p[i] - ch[m - ])) <= ) m--;
ch[m++] = p[i];
} int k = m;
for(int i = n - ; i >= ; i--) {
while(m > k && dcmp(Cross(ch[m - ] - ch[m - ], p[i] - ch[m - ])) <= ) m--;
ch[m++] = p[i];
}
return m;
} Point vec[], vec2[]; int main() {
scanf("%d", &n);
for(int i = ; i < n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y);
cnt = ConvexHull(p, n, ch); cnt--;
for(int i = ; i < cnt; i++) {
ch[cnt + i] = ch[i];
} int pos1 = , pos2 = , pos3 = ;
double ans = inf;
for(int i = ; i < cnt; i++) {
while(abs(Cross(ch[i] - ch[pos1 + ], ch[i + ] - ch[pos1 + ])) > abs(Cross(ch[i] - ch[pos1], ch[i + ] - ch[pos1])))
pos1++;
while(Dot(ch[i + ] - ch[i], ch[pos2 + ] - ch[i]) > Dot(ch[i + ] - ch[i], ch[pos2] - ch[i]))
pos2++;
pos3 = max(pos3, pos1);
while(Dot(ch[i + ] - ch[i], ch[pos3 + ] - ch[i]) < Dot(ch[i + ] - ch[i], ch[pos3] - ch[i]))
pos3++;
Vector k1 = ch[i + ] - ch[i];
Vector k2 = Rotate(k1, PI / );
Point p1 = GetLineIntersection(ch[i], k1, ch[pos2], k2);
Point p2 = GetLineIntersection(ch[i], k1, ch[pos3], k2);
Point p3 = GetLineIntersection(ch[pos1], k1, ch[pos2], k2);
Point p4 = GetLineIntersection(ch[pos1], k1, ch[pos3], k2);
double ret = dis(p1, p2) * dis(p1, p3);
if(ret < ans) {
ans = ret;
vec[] = p1;
vec[] = p2;
vec[] = p3;
vec[] = p4;
}
} ConvexHull(vec, , vec2);
printf("%.5f\n", ans);
for(int i = ; i < ; i++) {
printf("%.5f %.5f\n", vec2[i].x, vec2[i].y);
}
return ;
}
/*
*/
bzoj 1185的更多相关文章
- 洛谷 P3187 BZOJ 1185 [HNOI2007]最小矩形覆盖 (旋转卡壳)
题目链接: 洛谷 P3187 [HNOI2007]最小矩形覆盖 BZOJ 1185: [HNOI2007]最小矩形覆盖 Description 给定一些点的坐标,要求求能够覆盖所有点的最小面积的矩形, ...
- BZOJ 1185 最小矩形覆盖
Description Input Output Sample Input Sample Output HINT 其实这题就是一道旋转卡壳的裸题,但是我的精度萎了.直接上hzwer的代码吧... #i ...
- BZOJ:1185: [HNOI2007]最小矩形覆盖
1185: [HNOI2007]最小矩形覆盖 这计算几何……果然很烦…… 发现自己不会旋转卡壳,补了下,然后发现求凸包也不会…… 凸包:找一个最左下的点,其他点按照与它连边的夹角排序,然后维护一个栈用 ...
- BZOJ 1185: [HNOI2007]最小矩形覆盖 [旋转卡壳]
1185: [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1435 Solve ...
- ●BZOJ 1185 [HNOI2007]最小矩形覆盖
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解: 计算几何,凸包,旋转卡壳 结论:矩形的某一条边在凸包的一条边所在的直线上. ( ...
- bzoj 1185 [HNOI2007]最小矩形覆盖——旋转卡壳
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 矩形一定贴着凸包的一条边.不过只是感觉这样. 枚举一条边,对面的点就是正常的旋转卡壳. ...
- BZOJ 1185 [HNOI2007]最小矩形覆盖:凸包 + 旋转卡壳
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 题意: 给出二维平面上的n个点,问你将所有点覆盖的最小矩形面积. 题解: 先找出凸 ...
- BZOJ 1185: [HNOI2007]最小矩形覆盖-旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标-备忘板子
来源:旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标 BZOJ又崩了,直接贴一下人家的代码. 代码: #include"stdio.h" #include"str ...
- bzoj 1185 最小矩形覆盖 —— 旋转卡壳
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 枚举一条边,维护上.左.右方的点: 上方点到这条边距离最远,所以用叉积求面积维护: 左 ...
- bzoj 1185 [HNOI2007]最小矩形覆盖 凸包+旋转卡壳
题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...
随机推荐
- How to 对拍?
对拍从数学的统计学角度来说是一个好的方法,至少能在你竞赛中帮你拿回一些分--yzr大牛pas的对拍一开始还没写过,突然想学一下对拍.那么就学吧.dp水题(搜索):https://www.luogu.o ...
- VS2017企业版本(安装包+key)+ .NET Reflector 9.0
关于VS2017安装的一点扩充说明(15.5):http://www.cnblogs.com/dunitian/p/8051985.html Key激活无需断网 Visual Studio 2017 ...
- E. The Supersonic Rocket Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)
http://codeforces.com/contest/1017/problem/E 凸包模板+kmp #include <cstdio> #include <cstdlib&g ...
- pyspider框架的599证书问题
使用PySpider 框架出现错误 HTTP 599: SSL certificate problem: unable to get local issuer certificate,如下 HTTP ...
- Python 堆与堆排序
堆排序与快速排序,归并排序一样都是时间复杂度为O(N*logN)的几种常见排序方法.学习堆排序前,先讲解下什么是数据结构中的二叉堆. 二叉堆的定义 二叉堆是完全二叉树或者是近似完全二叉树. 二叉堆满足 ...
- webpack插件去除没用到的css
去除没用到的css需要用到purifycss-webpack插件,而这个插件又依赖于purify-css 1.安装 npm i purifycss-webpack purify-css -D 2.加入 ...
- Java基础-SSM之mybatis一对一外键关联
Java基础-SSM之mybatis一对一外键关联 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.准备测试环境(创建数据库表) 1>.创建husbandsfk和wife ...
- 论文中“but”与“however”的区别
- CSS-3 圆角Border-radius 的使用
那么早些年 圆角其实是有的,后来的草案中将它去掉了,现在从CSS3开始,又加入了回来.可以看出圆角的使用还是非常广泛的. 那么在圆角还没有被加入进来之前,我们要实现圆角的效果,可能就是需要IMG图片来 ...
- Linux - sed 文本操作
SED 是一项Linux指令,功能同awk类似,差别在于,sed简单,对列处理的功能要差一些,awk的功能复杂,对列处理的功能比较强大. sed全称是:Stream EDitor 调用sed命令有两种 ...