UVALive 4728 Squares(旋转卡壳)
Squares
The famous Korean IT company plans to make a digital map of the Earth with help of wireless sensors which spread out in rough terrains. Each sensor sends a geographical data to
. But, due to the inaccuracy of the sensing devices equipped in the sensors,
only knows a square region in which each geographical data happens. Thus a geographical data can be any point in a square region. You are asked to solve some geometric problem, known as diameter problem, on these undetermined points in the squares.
A diameter for a set of points in the plane is defined as the maximum (Euclidean) distance among pairs of the points in the set. The diameter is used as a measurement to estimate the geographical size of the set. wants you to compute the largest diameter of the points chosen from the squares. In other words, given a set of squares in the plane, you have to choose exactly one point from each square so that the diameter for the chosen points is maximized. The sides of the squares are parallel to X-axis or Y-axis, and the squares may have different sizes, intersect each other, and share the same corners.
For example, if there are six squares as in the figure below, then the largest diameter is defined as the distance between two corner points of squares S1 and S4.

Given a set of n squares in the plane, write a program to compute the largest diameter D of the points when a point is chosen from each square, and to output D2, i.e., the squared value of D.
Input
Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. The first line of each test case contains an integer, n, the number of squares, where 2n
100, 000. Each line of the next n lines contains three integers, x, y, and w, where (x, y) is the coordinate of the left-lower corner of a square and w is the length of a side of the square; 0
x, y
10, 000 and 1
w
10, 000.
Output
Your program is to write to standard output. Print exactly one line for each test case. The line should contain the integral value D2, whereD is the largest diameter of the points when a point is chosen from each square.
The following shows sample input and output for two test cases.
Sample Input
2
3
0 0 1
1 0 2
0 0 1
6
2 1 2
1 4 2
3 2 3
4 4 4
6 5 1
5 1 3
Sample Output
13
85
求出矩阵那些点中,最远的两个点。
那么先求出凸包,然后再用旋转卡壳来弄出最大。
刚刚学卡壳的一到题。
WA在了设置初始对踵点,不可把对踵点设为第一个点,要设成第二个点。
这里我不太懂。
#include <bits/stdc++.h>
using namespace std;
const int N = ;
int n , tot ;
struct Point {
int x , y ;
Point(){};
Point(int a , int b ){x=a,y=b;}
bool operator < ( const Point &a ) const {
if( x != a.x )return x < a.x ;
else return y < a.y ;
}
}p[N<<],ch[N<<]; inline int Cross( Point a , Point b ) { return a.x*b.y-a.y*b.x ; }
inline int dis( Point a , Point b ) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
Point operator - ( Point a , Point b ) { return Point(a.x-b.x,a.y-b.y); }
int ConvexHull( Point* p , int n , Point* ch ){ int m = ;
sort( p , p + n );
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 Rotating_Calipers( Point* poly , int n ) { int j = , ans = ;
poly[n] = poly[] ;
for( int i = ; i < n ; ++i ) {
while( fabs( Cross(poly[i+]-poly[i],poly[j]-poly[i]) ) < fabs( Cross(poly[i+]-poly[i],poly[j+]-poly[i]))) j=(j+)%n ;
ans = max( ans , max( dis(poly[i],poly[j]) , dis(poly[i+] ,poly[j])));
}
return ans ;
} void Run() {
int x , y , w ;
scanf("%d",&n);
tot = ;
for( int i = ; i < n ; ++i ) {
scanf("%d%d%d",&x,&y,&w);
p[tot++]=Point(x,y);
p[tot++]=Point(x+w,y);
p[tot++]=Point(x+w,y+w);
p[tot++]=Point(x,y+w);
}
int m = ConvexHull( p , tot , ch );
printf("%d\n",Rotating_Calipers(ch,m));
} int main(){
int _ ; scanf("%d",&_);
while(_--) Run();
}
UVALive 4728 Squares(旋转卡壳)的更多相关文章
- UVAL 4728 Squares(旋转卡壳)
Squares [题目链接]Squares [题目类型]旋转卡壳 &题解: 听着算法名字,感觉挺难,仔细一看之后,发现其实很简单,就是依靠所构成三角行面积来快速的找对踵点,就可以省去很多的复杂 ...
- UVALive 4728 Squares (平面最远点对)
题意:n个平行于坐标轴的正方形,求出最远点对的平方 题解:首先求出凸包,可以证明最远点对一定是凸包上的点对,接着可以证明最远点对(每个点的对踵点)一定只有3*n/2对 接着使用旋转卡壳找到最远点对,但 ...
- UVa 1453 - Squares 旋转卡壳求凸包直径
旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...
- uvalive 4728 Squares
题意:求所有正方形中两点距离最大值的平方值. 思路:旋转卡壳法. 分别用数组和vector存凸包时,旋转卡壳代码有所不同. #include<cstdio> #include<cma ...
- LA 4728 (旋转卡壳) Squares
题意: 求平面上的最远点对距离的平方. 分析: 对于这个数据量枚举肯定是要超时的. 首先这两个点一定是在凸包上的,所以可以枚举凸包上的点,因为凸包上的点要比原来的点会少很多,可最坏情况下的时间复杂度也 ...
- UVA 4728 Squares(凸包+旋转卡壳)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...
- LA 4728 旋转卡壳算法求凸包的最大直径
#include<iostream> #include<cstdio> #include<cmath> #include<vector> #includ ...
- 1393: Robert Hood 旋转卡壳 凸包
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1393 http://poj.org/problem?id=2187 Beauty Contest ...
- POJ 3608 Bridge Across Islands --凸包间距离,旋转卡壳
题意: 给你两个凸包,求其最短距离. 解法: POJ 我真的是弄不懂了,也不说一声点就是按顺时针给出的,不用调整点顺序. 还是说数据水了,没出乱给点或给逆时针点的数据呢..我直接默认顺时针给的点居然A ...
随机推荐
- java crm 系统 进销存 springmvc SSM项目项目源码
统介绍: 1.系统采用主流的 SSM 框架 jsp JSTL bootstrap html5 (PC浏览器使用) 2.springmvc +spring4.3.7+ mybaits3.3 SSM 普 ...
- Windows下svn使用教程
SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subversion是什么? ...
- 【转载】Spring bean 中 constructor-arg属性
转载地址:https://blog.csdn.net/qq_27292113/article/details/78063696 方便以后查阅
- rlogin - 远程注册
SYNOPSIS(总览) rlogin [-8EKLdx ] [-e char ] [-l username ] host DESCRIPTION(描述) Rlogin 在远程主机 host 上开始 ...
- 13-H.264编码解码器的无线应用:1080P60 3D无线影音传输器
H.264编码解码器的无线应用:1080P60 3D无线影音传输器 一.应用领域 家庭媒体娱乐中心 新闻现场采访 无线3D投影机 高清视频会议终端无线延长器 教学,医疗示教 考古,高档商业区域,监狱等 ...
- python如何简单的处理图片(1):打开\显示
一提到数字图像处理,可能大多数人就会想到matlab,但matlab也有自身的缺点: 1.不开源,价格贵 2.软件容量大.一般3G以上,高版本甚至达5G以上. 3.只能做研究,不易转化成软件. 因此, ...
- java 抽象的概念 抽象类的使用
package java10; /* 抽象方法:就是加上abstract关键字,然后去掉大括号,直接分号结束 抽象类:抽象方法所在的类,必须是抽象类才行.在class之前写上abstract即可 如何 ...
- grep正则 以.o结尾的文件
ls -l | grep *.o 查不出任何东西 . 代表一定有一个任意字符 * 重复零个到无穷多个前一个字符(所以需要前面有字符) 所以应该是 ls -l | grep '.*\.o' .*表示零个 ...
- windows平台搭建Mongo数据库复制集(类似集群)(二)
通过rs.status()命令我们可以查询到各个节点运行正常. 一.数据同步测试 在28011.28012端口上进行插入: 因为SECONDARY是不允许读写的, 在写多读少的应用中,使用Replic ...
- html5 lineTo的使用例子
demo.js function draw(id) { var CANVAS=document.getElementById(id); var context=CANVAS.getContext('2 ...