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]最小矩形覆盖 凸包+旋转卡壳
题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...
随机推荐
- 适用于vue项目的打印插件(转载)
出处:https://www.cnblogs.com/lvyueyang/p/9847813.html // 使用时请尽量在nickTick中调用此方法 //打印 export default (re ...
- 本地如何连接虚拟机上的MySql
今天在本地链接虚拟机上的MySql,然而链接失败了!甚是尴尬! 首先想一想是什么原因导致链接失败: 基础环境:在Linux上安装mysql 1.检查虚拟机IP在本地是否可以ping 通过 虚拟机IP: ...
- websoclet简单示例 my 改
首先,创建一个 maven war 项目: 首先,pom文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmln ...
- Centos 搭建 http服务器
1,安装 yum install httpd 2,查看是否安装成功 netstat [root@localhost ~]# netstat -anp | grep 80 tcp 0 0 :: ...
- Redis记录-Redis高级应用
Redis数据库可以使用安全的方案,使得进行连接的任何客户端在执行命令之前都需要进行身份验证.要保护Redis安全,需要在配置文件中设置密码. 示例 下面的示例显示了保护Redis实例的步骤. 127 ...
- bzoj千题计划270:bzoj4559: [JLoi2016]成绩比较(拉格朗日插值)
http://www.lydsy.com/JudgeOnline/problem.php?id=4559 f[i][j] 表示前i门课,有j个人没有被碾压的方案数 g[i] 表示第i门课,满足B神排名 ...
- Linux命令(三)远程登录
- [转载]Supporting OData $inlinecount with the new Web API OData preview package
http://www.strathweb.com/2012/08/supporting-odata-inlinecount-with-the-new-web-api-odata-preview-pac ...
- CS229 笔记08
CS229 笔记08 Kernel 回顾之前的优化问题 原始问题为: \[ \min_{w,b} \frac{1}{2}||w||^2\\[1.5em] {\text{s.t.}}y^{(i)}\le ...
- 在 Linux 中安装 VMware Tools
由于较新的Linux版本中都包含了vm的部分组件,导致直接安装VMware Tools失败.所以这里写了篇新的. 软件版本:VMware 12 Linux版本:Ubuntu Desktop 16.04 ...