题目: Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the title 'Miss Cow World'. As a result, Bessie will make a tour of N (2 <= N <= 50,000) farms around the world in order to spread goodwill…
题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412.html 或 http://cgm.cs.mcgill.ca/~orm/rotcal.frame.html #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #includ…
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the title 'Miss Cow World'. As a result, Bessie will make a tour of N (2 <= N <= 50,000) farms around the world in order to spread goodwill between farm…
[BZOJ1185][HNOI2007]最小矩形覆盖(凸包,旋转卡壳) 题面 BZOJ 洛谷 题解 最小的矩形一定存在一条边在凸包上,那么枚举这条边,我们还差三个点,即距离当前边的最远点,以及做这条边的垂线的最靠左和最靠右的两个点. 最远点很容易求,叉积计算面积来比就好了. 那么剩下两个点呢? 比如说找右侧的那个点,我们假装当前枚举出来的这条边就是水平线,那么只要当前的点和下一个点的直线与\(x\)轴正半轴夹角小于\(90°\) 显然就往这个方向走.然后从水平线换到一般的情况,也就是和枚举的这条…
传送门 在这里假设可以选择两个相同的点吧-- 那么选出来的四个点一定会在凸包上 建立凸包,然后枚举这个四边形的对角线.策略是先枚举对角线上的一个点,然后沿着凸包枚举另一个点.在枚举另一个点的过程中可以使用旋转卡壳找到在对角线两侧.距离对角线最远的两个点,这样的四个点就可以贡献答案.总时间复杂度\(O(n^2)\) #include<iostream> #include<cstdio> #include<cstdlib> #include<ctime> #in…
传送门 首先,肯定只有凸包上的点会限制这个矩形,所以建立凸包. 然后可以知道,矩形上一定有一条边与凸包上的边重合,否则可以转一下使得它重合,答案会更小. 于是沿着凸包枚举这一条边,通过旋转卡壳找到离这条边最远的点以及这个矩形两端的点,这五个点构成的矩形就是一个可能的答案了. 各种判断用向量叉积和点积 注意一下输出\(-0.0000\)的情况 #include<bits/stdc++.h> #define ld long double #define eps 1e-8 //This code i…
题目链接 又调了我两个多小时巨亏 直接\(O(n^4)\)枚举4个点显然不行. 数据范围提示我们需要一个\(O(n^2)\)的算法. 于是\(O(n^2)\)枚举对角线,然后在这两个点两边各找一个点使其和对角线构成的三角形面积最大,也就是叉积的绝对值最大.显然具有单调性,于是旋转卡壳维护. #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const int MAXN…
题目链接 嗯,毒瘤题. 首先有一个结论,就是最小矩形一定有条边和凸包重合.脑补一下就好了. 然后枚举凸包的边,用旋转卡壳维护上顶点.左端点.右端点就好了. 上顶点用叉积,叉积越大三角形面积越大,对应的高也就越大.两边的点用点积,点积越大投影越大. 然后就是精度问题.这种实数计算最好不要直接用比较运算符,要用差和\(eps\)的关系来比较,我就是一直卡在这里.还好有爆炸\(OJ\)离线题库提供的数据... #include <cstdio> #include <cmath> #inc…
题目链接 旋转卡壳模板题把. 有时间再补总结吧. #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const int MAXN = 100010; struct point{ int x, y; }p[MAXN]; int operator * (point a, point b){ // a x b return a.x * b.y - b.x * a.y; }…
题目大意: 求最远点对距离 求凸包上的最远点对 挑战263页 #include <cstdio> #include <string.h> #include <algorithm> #include <vector> #include <cmath> using namespace std; ; ; int n; double add(double a,double b) { ; return a+b; } struct P { double x,…