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]最小矩形覆盖 凸包+旋转卡壳
题目大意 用最小矩形覆盖平面上所有的点 分析 有一结论:最小矩形中有一条边在凸包的边上,不然可以旋转一个角度让面积变小 简略证明 我们逆时针枚举一条边 用旋转卡壳维护此时最左,最右,最上的点 注意 注 ...
随机推荐
- oracle函数验证时间格式并返回
CREATE OR REPLACE FUNCTION WSW(parameter VARCHAR2) RETURN DATE IS val DATE; BEGIN IF (REGEXP_INSTR(p ...
- Spring Boot -Shiro配置多Realm
核心类简介 xxxToken:用户凭证 xxxFilter:生产token,设置登录成功,登录失败处理方法,判断是否登录连接等 xxxRealm:依据配置的支持Token来认证用户信息,授权用户权限 ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- 【BZOJ4870】组合数问题(动态规划,矩阵快速幂)
[BZOJ4870]组合数问题(动态规划,矩阵快速幂) 题面 BZOJ 洛谷 题解 显然直接算是没法做的.但是要求的东西的和就是从\(nk\)个物品中选出模\(k\)意义下恰好\(r\)个物品的方案数 ...
- CodeSmith自己动手写模板
CodeSmith学习笔记------ 1.新建一个Code Smith Generator Template(C sharp) 2.一些常见标签的解释: ①外部变量: <%@ Property ...
- 解题:UOJ #46 玄学
题面 二进制分组,修改把区间拆开丢在后面,合并的时候归并最后两块:查询在对应节点上二分答案 #include<cstdio> #include<cstring> #includ ...
- Logistic回归中损失函数求导证明过程
- valgrind使用指南
http://note.youdao.com/noteshare?id=5de9c049ccdb1defdc4368db83813dd3
- json字符串转java对象
今天遇到一个问题,前端ajax获取到一个javaBean对象,好多方法发ajax请求需要把这个对象再传到后端,后端再根据这个对象进行操作(之前计划传递id,但发现传递id的话,后端多个方法都需要根据i ...
- vue-router基本概念及使用
index.html: <!DOCTYPE html> <html> <head> <title></title> <meta cha ...