UVa 1453 - Squares 旋转卡壳求凸包直径
旋转卡壳求凸包直径。
参考: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 旋转卡壳求凸包直径的更多相关文章
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- bzoj1185 [HNOI2007]最小矩形覆盖 旋转卡壳求凸包
[HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2081 Solved: 920 ...
- Bridge Across Islands POJ - 3608 旋转卡壳求凸包最近距离
\(\color{#0066ff}{题目描述}\) 几千年前,有一个小王国位于太平洋的中部.王国的领土由两个分离的岛屿组成.由于洋流的冲击,两个岛屿的形状都变成了凸多边形.王国的国王想建立一座桥来连接 ...
- POJ 2079 Triangle 旋转卡壳求最大三角形
求点集中面积最大的三角形...显然这个三角形在凸包上... 但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了... 随着底边点的递增, 最大点显然是在以 ...
- POJ2187 旋转卡壳 求最长直径
给定平面上的一些散点集,求最远两点距离的平方值. 题解: 旋转卡壳求出凸包,然后根据单调性,求出最远两点的最大距离 #pragma GCC optimize(2) #pragma G++ optimi ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- [hdu5251]矩形面积 旋转卡壳求最小矩形覆盖
旋转卡壳求最小矩形覆盖的模板题. 因为最小矩形必定与凸包的一条边平行,则枚举凸包的边,通过旋转卡壳的思想去找到其他3个点,构成矩形,求出最小面积即可. #include<cstdio> # ...
- 「POJ-3608」Bridge Across Islands (旋转卡壳--求两凸包距离)
题目链接 POJ-3608 Bridge Across Islands 题意 依次按逆时针方向给出凸包,在两个凸包小岛之间造桥,求最小距离. 题解 旋转卡壳的应用之一:求两凸包的最近距离. 找到凸包 ...
随机推荐
- SQLdiag Utility
使用SQLdiag 会进行信息搜集类型 Windows 系统性能日志 Windows 系统日志 SQL Server 性能信息 SQL Server 阻塞信息 SQL Server 配置信息 如何使用 ...
- 第六周 N题
Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (h ...
- Jackson怎样转换这样的字符串? String jsonStr = "{dataType:'Custom',regexp:'t\\d+',msg:'输入不正确'}";
字符串 String jsonStr = "{dataType:'Custom',regexp:'t\\d+',msg:'输入不正确'}"; 实体 package com.asia ...
- Linux之mount命令详解
linux下挂载(mount)光盘映像文档.移动硬盘.U盘.Windows和NFS网络共享linux是个优秀的开放源码的操作系统,能够运行在大到巨型小到掌上型各类电脑系统上,随着linux系统的日渐成 ...
- 10大iOS开发者最喜爱的类库
该10大iOS开发者最喜爱的库由“iOS辅导团队”成员Marcelo Fabri组织投票选举而得,参与者包括开发者团队,iOS辅导团队以及行业嘉宾.每个团队都要根据以下规则选出五个最好的库:1)不能投 ...
- JDBC 学习笔记(一)—— 基础知识 + 分页技术
本文目录: 1.JDBC简介 2.使用JDBC的步骤——第一个JDBC程序 3.DriverManager ——加载数据库驱动 4.数据库URL ——标识数据库的 ...
- JSP访问Spring中的bean
JSP访问Spring中的bean <%@page import="com.sai.comment.po.TSdComment"%> <%@page import ...
- c++ std::string 用法
std::string用法总结 在平常工作中经常用到了string类,本人记忆了不好用到了的时候经常要去查询.在网上摘抄一下总结一下,为以后的查询方便: string类的构造函数: string(co ...
- [转载]GDI+中发生一般性错误
注:第一次写博客,把自己遇到的问题和收集的资料记录在博客上.在开发.NET应用中,使用 System.Drawing.Image.Save 方法而导致“GDI+ 中发生一般性错误”的发生,通常有以下三 ...
- d3d11 effect state and default value tables
Blend state State Default ValueAlphaToCoverage Enable FALSEIndependentBlend Enable FALSERenderTarget ...