旋转卡壳求凸包直径。

参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html

 #include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; const int MAXN = << ; struct Point
{
int x, y;
Point( int x = , int y = ):x(x), y(y) { }
}; typedef Point Vector; Vector operator+( Vector A, Vector B ) //向量加
{
return Vector( A.x + B.x, A.y + B.y );
} Vector operator-( Vector A, Vector B ) //向量减
{
return Vector( A.x - B.x, A.y - B.y );
} Vector operator*( Vector A, double p ) //向量数乘
{
return Vector( A.x * p, A.y * p );
} Vector operator/( Vector A, double p ) //向量数除
{
return Vector( A.x / p, A.y / p );
} bool operator<( const Point& A, const Point& B ) //两点比较
{
return A.x < B.x || ( A.x == B.x && A.y < B.y );
} double Cross( Vector A, Vector B ) //向量叉积
{
return A.x * B.y - A.y * B.x;
} int ConvexHull( Point *p, int n, Point *ch )
{
sort( p, p + n );
int m = ;
for ( int i = ; i < n; ++i )
{
while ( m > && 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 && Cross( ch[m - ] - ch[m - ], p[i] - ch[m - ] ) <= ) --m;
ch[m++] = p[i];
} if ( n > ) --m;
return m;
} int dist( Point a, Point b )
{
return (a.x - b.x)*(a.x - b.x)+(a.y - b.y)*(a.y - b.y);
} int RotatingCalipers( Point *ch, int n )
{
int q = ;
int ans = ;
for ( int i = ; i < n; ++i )
{
while ( Cross( ch[i + ] - ch[i], ch[q + ] - ch[i] ) > Cross( ch[i + ] - ch[i], ch[q] - ch[i] ) )
q = ( q + ) % n;
ans = max( ans, max( dist( ch[i], ch[q] ), dist( ch[i + ], ch[q + ] ) ) );
}
return ans;
} Point read_Point( int x, int y )
{
return Point( x, y );
} Point P[MAXN], ch[MAXN]; int main()
{
int T;
scanf( "%d", &T );
while ( T-- )
{
int N, cnt = ;
scanf( "%d", &N );
for ( int i = ; i < N; ++i )
{
int x, y, len;
scanf( "%d%d%d", &x, &y, &len );
P[cnt++] = read_Point( x, y );
P[cnt++] = read_Point( x + len, y );
P[cnt++] = read_Point( x, y + len );
P[cnt++] = read_Point( x + len, y + len );
} int m = ConvexHull( P, cnt, ch );
printf("%d\n", RotatingCalipers( ch, m ) );
}
return ;
}

UVa 1453 - Squares 旋转卡壳求凸包直径的更多相关文章

  1. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  2. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  3. bzoj1185 [HNOI2007]最小矩形覆盖 旋转卡壳求凸包

    [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2081  Solved: 920 ...

  4. Bridge Across Islands POJ - 3608 旋转卡壳求凸包最近距离

    \(\color{#0066ff}{题目描述}\) 几千年前,有一个小王国位于太平洋的中部.王国的领土由两个分离的岛屿组成.由于洋流的冲击,两个岛屿的形状都变成了凸多边形.王国的国王想建立一座桥来连接 ...

  5. POJ 2079 Triangle 旋转卡壳求最大三角形

    求点集中面积最大的三角形...显然这个三角形在凸包上... 但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了... 随着底边点的递增, 最大点显然是在以 ...

  6. POJ2187 旋转卡壳 求最长直径

    给定平面上的一些散点集,求最远两点距离的平方值. 题解: 旋转卡壳求出凸包,然后根据单调性,求出最远两点的最大距离 #pragma GCC optimize(2) #pragma G++ optimi ...

  7. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

  8. [hdu5251]矩形面积 旋转卡壳求最小矩形覆盖

    旋转卡壳求最小矩形覆盖的模板题. 因为最小矩形必定与凸包的一条边平行,则枚举凸包的边,通过旋转卡壳的思想去找到其他3个点,构成矩形,求出最小面积即可. #include<cstdio> # ...

  9. 「POJ-3608」Bridge Across Islands (旋转卡壳--求两凸包距离)

    题目链接 POJ-3608 Bridge Across Islands 题意 依次按逆时针方向给出凸包,在两个凸包小岛之间造桥,求最小距离. 题解 旋转卡壳的应用之一:求两凸包的最近距离. 找到凸包 ...

随机推荐

  1. MySQL主从同步报Client requested master to start replication from position

    数据库版本:5.6.16 测试环境MySQL 主从,数据库被人重启,忘记开启start slave,导致主从失效,停了一天的数据没有追上. 查看从库的数据库状态:show   slave   stat ...

  2. IOS仿Android九宫格解锁效果[转]

    原理很简单,监听view中touch的一系列事件,当判定手指位置在某个按钮附近的时候则判断此按钮选中,并画出线. 效果图如下: 你可以在NineGridUnlockView.m文件中方法 touche ...

  3. (转) java 复制文件,不使用输出流复制,高效率,文件通道的方式复制文件

    public static void fileChannelCopy(File s, File t) { FileInputStream fi = null; FileOutputStream fo ...

  4. Eclipse启动的时候窗口一闪就关的解决办法(转)

    有时候会碰到如题这种问题,从网上查知解决办法,非常管用 为eclipse.exe创建一个快捷方式,然后快捷方式上右键-属性,在目标栏填入 E:\eclipse\eclipse.exe -vm &quo ...

  5. SVN的405错误

    错误1: 如果你没有阅读以下文字,活该你倒霉(这段文字是在googlecode添加新项目时生成的): Command-line access If you plan to make changes, ...

  6. Mysql创建和删除用户

    问题描述:        Mysql中创建用户和删除用户 问题解决:     (1)查询Mysql当前登录账户     (2)创建用户     方法一: 创建用户赋予用户所有权限: 新创建的用户可以在 ...

  7. BZOJ 4341 [CF253 Printer] 解题报告

    乍一看这个题好像可以二分优先度搞搞... 实际上能不能这么搞呢...? 我反正不会... 于是开始讲我的乱搞算法: 首先肯定要把任务按照优先度排序. 用一棵在线建点的线段树维护一个时刻是否在工作. 然 ...

  8. 【POJ】【1741】/【BZOJ】【1468】Tree

    点分治 怎么又一道叫Tree的题目……真是醉了. 本题为漆子超论文<分治算法在树的路径问题中的应用>例一 题解 : http://blog.csdn.net/sdj222555/artic ...

  9. Machine Learning Done Wrong

    Machine Learning Done Wrong Statistical modeling is a lot like engineering. In engineering, there ar ...

  10. uva 307

    排序之后再剪枝,有点神 #include <cstdio> #include <cstdlib> #include <cmath> #include <map ...