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]最小矩形覆盖 凸包+旋转卡壳
题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...
随机推荐
- 【刷题】洛谷 P4782 【模板】2-SAT 问题
题目背景 2-SAT 问题 模板 题目描述 有n个布尔变量 \(x_1\)~\(x_n\),另有m个需要满足的条件,每个条件的形式都是"\(x_i\)为true/false或\(x_j ...
- HGOI20181029模拟题解
HGOI20181029模拟题解 /* sxn让我一定要谴责一下出题人和他的数据! */ problem: 给出十进制数a,b,然后令(R)10=(a)10*(b)10,给出c表示一个k进制数(1&l ...
- 上传文件到aws的s3存储
只要有aws-cli客户端就可以上传文件到aws的S3存储.可以在任意机器上.这里以centos为例. 1.安装python.pip. # yum install -y python python-p ...
- GDKOI2018发烧记
偏远小渔村NOIP螺旋升天选手又一次来到了广州参加GDKOI...金实的初三爷们也来啦?要被碾啦T T Day 0 跟HR Lao爷拼(biao)车到了高铁站,上了高铁居然没有颓颓颓吃吃吃(雾),安心 ...
- 人生效率手册:如何卓有成效地过好每一天--By张萌姐姐--读书笔记
读书笔记:<人生效率手册>:如何卓有成效地过好每一天--By张萌姐姐... 整本书看完的感受: 这本书主要讲的是生活中我们需要给自己一个目标,然后通过自己的努力去实现这个目标,书中说的很多 ...
- POJ 3252 Round Number(数位DP)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6983 Accepted: 2384 Des ...
- bzoj千题计划221:bzoj1500: [NOI2005]维修数列(fhq treap)
http://www.lydsy.com/JudgeOnline/problem.php?id=1500 1.覆盖标记用INF表示无覆盖标记,要求可能用0覆盖 2.代表空节点的0号节点和首尾的两个虚拟 ...
- 五行代码终极完美解决从IE6到Chrome所有浏览器的position:fixed;以及闪动问题
这个方法其实已经使用很久了,之前主要在嵌入式WebQQ等产品中用过,现在拿出来分享一下吧,是目前最简洁的方式来实现ie6的position:fixed; 失效bug,以及的其他方法的闪动问题,CSS代 ...
- bug处理
当提示405 method not allowed 时候,路由可能有问题,看看路由是get/post 是否合格
- 记webpack下引入vue的方法(非.vue文件方式)
直接script引入下载静态的vue.js文件则最后用copy-webpack-plugin复制到一样的目录即可 使用npm安装的vue无法直接用 import vue from "vue& ...