题目大意: 给你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的更多相关文章

  1. 洛谷 P3187 BZOJ 1185 [HNOI2007]最小矩形覆盖 (旋转卡壳)

    题目链接: 洛谷 P3187 [HNOI2007]最小矩形覆盖 BZOJ 1185: [HNOI2007]最小矩形覆盖 Description 给定一些点的坐标,要求求能够覆盖所有点的最小面积的矩形, ...

  2. BZOJ 1185 最小矩形覆盖

    Description Input Output Sample Input Sample Output HINT 其实这题就是一道旋转卡壳的裸题,但是我的精度萎了.直接上hzwer的代码吧... #i ...

  3. BZOJ:1185: [HNOI2007]最小矩形覆盖

    1185: [HNOI2007]最小矩形覆盖 这计算几何……果然很烦…… 发现自己不会旋转卡壳,补了下,然后发现求凸包也不会…… 凸包:找一个最左下的点,其他点按照与它连边的夹角排序,然后维护一个栈用 ...

  4. BZOJ 1185: [HNOI2007]最小矩形覆盖 [旋转卡壳]

    1185: [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1435  Solve ...

  5. ●BZOJ 1185 [HNOI2007]最小矩形覆盖

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解: 计算几何,凸包,旋转卡壳 结论:矩形的某一条边在凸包的一条边所在的直线上. ( ...

  6. bzoj 1185 [HNOI2007]最小矩形覆盖——旋转卡壳

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 矩形一定贴着凸包的一条边.不过只是感觉这样. 枚举一条边,对面的点就是正常的旋转卡壳. ...

  7. BZOJ 1185 [HNOI2007]最小矩形覆盖:凸包 + 旋转卡壳

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 题意: 给出二维平面上的n个点,问你将所有点覆盖的最小矩形面积. 题解: 先找出凸 ...

  8. BZOJ 1185: [HNOI2007]最小矩形覆盖-旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标-备忘板子

    来源:旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标 BZOJ又崩了,直接贴一下人家的代码. 代码: #include"stdio.h" #include"str ...

  9. bzoj 1185 最小矩形覆盖 —— 旋转卡壳

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 枚举一条边,维护上.左.右方的点: 上方点到这条边距离最远,所以用叉积求面积维护: 左 ...

  10. bzoj 1185 [HNOI2007]最小矩形覆盖 凸包+旋转卡壳

    题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...

随机推荐

  1. C++ pbds 库平衡树(tree)

    头文件 #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> //或者直接 ...

  2. 自定义Kettle数据库插件

    项目需要实现使用Kettle向神通数据库中写入数据,Kettle官方标准的数据库插件里面并没有对神通数据库的支持,因此需要自己写一个数据库插件.下面我们开始写一个数据库插件 1.在eclipse中创建 ...

  3. 用Python建设企业认证和权限控制平台

    目前大家对Python的了解更多来源是数据分析.AI.运维工具开发,在行业中使用Python进行web开发,同样也是非常受欢迎的,例如:FaceBook,豆瓣,知乎,饿了么等等,本文主要是介绍是利用P ...

  4. 内置函数sorted()

    这里顺便说一下sorted()和sort()的异同. sort 是 list 中的方法,只能对列表排序:sorted 可以对所有可迭代对象进行排序. list 的 sort 方法是对原列表进行操作,而 ...

  5. 前端学习 -- Css -- 文本标签

    em和strong - 这两个标签都表示一个强调的内容, em主要表示语气上的强调,em在浏览器中默认使用斜体显示 strong表示强调的内容,比em更强烈,默认使用粗体显示 <!DOCTYPE ...

  6. oracle递归查询(查询条件ID下得所有子集)

    一.CREATE TABLE TBL_TEST ( ID    NUMBER, NAME  VARCHAR2(100 BYTE), PID   NUMBER                       ...

  7. dedecms添加文章时提示标题为空,编辑文章时编辑器空白的解决办法

    dedecms添加文章时提示标题为空,编辑文章时编辑器空白的解决办法 dedecms出现这个问题与代码无关,主要是和PHP的版本有关,用的PHP5.4,更换成PHP5.2之后就不会有这个问题了. 问题 ...

  8. Codeforces Round #481 (Div. 3) G. Petya's Exams

    http://codeforces.com/contest/978/problem/G 感冒是真的受不了...敲代码都没力气... 题目大意: 期末复习周,一共持续n天,有m场考试 每场考试有如下信息 ...

  9. c#的委托用法delegate

  10. javascript鼠标拖拽的那些事情

    <html> <head> <title>javascript鼠标拖拽的那些事情</title> <meta http-equiv="C ...