[计算几何笔记2]旋转卡壳
来源:互联网 发布:最新免费x站地域名 编辑:程序博客网 时间:2024/06/13 04:15
POJ 2187
大概旋转卡壳就是这个意思了。。
int rotating_calipers(Point *ch, int m) /**旋转卡壳模板*/{ int q = 1; int ans = 0; ch[m] = ch[0]; /**凸包边界处理*/ for(int i = 0; i < m; i++) /**依次用叉积找出凸包每一条边对应的最高点*/ {/**同底不同高,每次用面积判断高的大小就可以了*/ while(Cross(ch[i+1]-ch[i], ch[q+1]-ch[i]) > Cross(ch[i+1]-ch[i], ch[q]-ch[i])) q = (q+1)%m; /**每条底上有两个点,所以要 max 两次*/ ans = max(ans, max(squarDist(ch[i], ch[q]), squarDist(ch[i+1], ch[q+1]))); } return ans;/**返回的也就是凸包的直径*/}
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#define maxn 200010using namespace std;//-------------------------------------------------------------//int n;struct Point{int x, y;bool operator<(const Point& k)const{if(x != k.x)return x < k.x;return y < k.y;}bool operator==(const Point& k)const{return x == k.x && y == k.y;}Point(int x = 0, int y = 0):x(x), y(y){}void read(){scanf("%d%d", &x, &y);}void print(){printf("%d %d\n", x, y);}}b[maxn], st[maxn], a[maxn];Point operator-(const Point& a, const Point& b){return Point(a.x - b.x, a.y - b.y);}int Cross(const Point& a, const Point& b){return a.x * b.y - a.y * b.x;}int length(const Point& k){return k.x * k.x + k.y * k.y;}const double eps = 1e-8;int Filter(double x){return x > eps ? 1 : (x < -eps ? -1 : 0);}//-------------------------------------------------------------//int main(){scanf("%d", &n);for(int i = 1; i <= n;i ++) b[i].read();sort(b+1, b+1+n);int top = 0;st[++ top] = b[1];st[++ top] = b[2];for(int i = 3; i <= n; i ++){while(top > 1 && Cross(st[top] - st[top - 1], b[i] - st[top - 1]) <= 0) top --;st[++ top] = b[i];}for(int i = 1; i <= top; i ++)a[i] = st[i];int cnt = top;top = 0;st[++ top] = b[n];st[++ top] = b[n - 1];for(int i = n - 2; i; i --){while(top > 1 && Cross(st[top] - st[top - 1], b[i] - st[top - 1]) <= 0) top --;st[++ top] = b[i];}for(int i = 1; i <= top; i ++){if(a[cnt] == st[i])continue;a[++ cnt] = st[i];}int ans = 0;int r = 2;a[cnt+1] = a[2];for(int i = 1; i < cnt; i ++){while(Cross(a[i+1] - a[i], a[r+1] - a[i]) > Cross(a[i+1] - a[i], a[r] - a[i]))r = r % cnt + 1;ans = max(length(a[r] - a[i]), ans);ans = max(length(a[r+1] - a[i+1]), ans);}printf("%d\n", ans);return 0;}
0 0
- [计算几何笔记2]旋转卡壳
- 计算几何学习笔记之旋转卡壳
- 计算几何——旋转卡壳【POJ2187】
- 计算几何——旋转卡壳
- 计算几何之旋转卡壳算法
- POJ 2187 计算几何之旋转卡壳
- Codeforces Round #358 (Div. 2) E 计算几何 旋转卡壳求最大三角形面积
- bzoj1069: [SCOI2007]最大土地面积 计算几何 旋转卡壳
- bzoj1185: [HNOI2007]最小矩形覆盖 计算几何 旋转卡壳
- 【BZOJ1185】最小矩形覆盖 计算几何 凸包 旋转卡壳
- 计算几何之凸包(三) {旋转卡壳初步}
- [计算几何][凸包][旋转卡壳] 最远距离点对
- POJ 2079(计算几何+凸包+旋转卡壳法)
- POJ 2187(计算几何+旋转卡壳法或暴力)
- <模板><计算几何>凸包-旋转卡壳最小面积外接矩形
- poj 2187 Beauty Contest 计算几何(凸包+旋转卡壳法)/最远点对
- ZOJ 2419-- Triangle-凸包+旋转卡壳求最大面积三角形(计算几何)
- 计算几何之二维凸包:卷包裹算法、Graham Scan Algorithm、旋转卡壳算法
- NSAttributedString属性详解
- 进程
- 使用ScrollView实现滚动
- 线性表之双链表--DoublyLinkList,类似于类库中的 LinkedList
- Android JNI打印信息
- [计算几何笔记2]旋转卡壳
- 生成 6 位随机数 验证码
- MFC SetTimer函数的用法
- 静态库和动态库基础
- HighCharts入门
- Qt 中定义单例对象
- Is the Information Reliable? -POJ2983差分约束
- 【SSH项目】在线支付功能解析
- java获取路径问题