旋转卡壳求凸包直径。

参考: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. 管理口令(P):[INS-30001] ADMIN口令为空之Oracle安装

    在安装oracle database11g 发行版的时候出现下面这个问题. 无论怎么输入密码都提示有问题,都输入得鬼火了!去百度了一下,果然有命名规则的 规则如下:小写字母+数字+大写字母

  2. 应用层HTTP,FTP,TFTP,TELNET,DNS,EMAIL

    ip路由选择 crc校验 数据包转发子模块 ttl值 ip输出队列/输入队列icmp报文 路由表 ip是网络层 tcp是传输层 应用层表示层会话层传输层网络层链路层物理层 网卡工作在链路层 网卡是工作 ...

  3. 【python】 入门 搭建环境

    1.去官网下载包 基本程序编译器 python-2.7.10.msi 集成开发环境 pycharm-community-4.5.2.exe 包管理工具 pip-7.0.3.tar.gz 2.安装 按顺 ...

  4. SharePoint 2010/SharePoint 2013 Custom Action: 基于Site Collection 滚动文字的通知.

    应用场景: 有时候我们的站点需要在每个页面实现滚动文字的通知,怎么在不修改Master Page的情况下实现这个功能?我们可以使用Javascript 和 Custom Action 来实现. 创建一 ...

  5. clion windows 开发配置

    1.下载clion 并且安装. 地址 : http://download-cf.jetbrains.com/cpp/clion-1.0.1.exe 2.安装cygwin  地址: https://cy ...

  6. Notes of the scrum meeting(10/31)

    meeting time:3:00~4:30p.m.,October 30th,2013 meeting place:绿园 attendees: 顾育豪                        ...

  7. WPF解析PPT为图片

    偶遇需要解析 PPT为单张图片 其中,对于包含动画的PPT页,分别对动画最后效果进行截取,即每个连续动画截取 (动画N个)N+1(原图)张 http://git.oschina.net/jiailiu ...

  8. try-catch-finally中return的执行情况分析

    try-catch-finally中return的执行情况分析: 1.在try中没有异常的情况下try.catch.finally的执行顺序 try --- finally 2.如果try中有异常,执 ...

  9. Codeforces Round #130 (Div. 2) A. Dubstep

    题目链接: http://codeforces.com/problemset/problem/208/A A. Dubstep time limit per test:2 secondsmemory ...

  10. Win7(包括32和64位)使用GitHub

    关于安装路径:32位可选择安装目录,但64位建议使用默认安装目录,否则Git Extensions配置会出问题 安装参考网址 http://code.google.com/p/tortoisegit/ ...