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 2
n
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 ...
随机推荐
- 监控软件之open-falcon
一.open-falcon介绍 1)中文社区介绍 http://book.open-falcon.org/zh_0_2/intro/ 参照文档: https://www.cnblogs.com/LAl ...
- web笔记全
1.项目流程与数据库 1.课程体系 阶段1(服务器开发): 项目导入/数据库/JS基础/NodeJS 阶段2(前端核心技术): HTML/AJAX/CSS/bootstrap 阶段3(前端进阶技术): ...
- 环境管理 pipenv 的 使用
安装 pip3 install pipenv 配置 配置 环境变量 WORKON_HOME , 表示 生成的虚拟环境 文件 的 存放位置 创建虚拟环境 方式一 pipenv --python 3.7 ...
- STREAM Benchmark及其操作性能分析
STREAM 是业界广为流行的综合性内存带宽实际性能 测量 工具之一.随着处理器处理核心数量的增多,内存带宽对于提升整个系统性能越发重要,如果某个系统不能够足够迅速地将内存中的数据传输到处理器当中,若 ...
- Spring入门-框架搭建
步骤: 导包 四个核心包: 日志包:由于市场上已经有更好的日志包,所以spring不用自己的,而是用apache的日志. 搞对象 由于spring是用来装对象的容器,所以得搞个对象让它装 书写配置文件 ...
- 神经网络学习笔记(二):feedforward和feedback
维基百科解释: Feed-forward, sometimes written feedforward, is a term describing an element or pathway with ...
- C#基础提升系列——C#异步编程
C#异步编程 关于异步的概述,这里引用MSDN的一段文字: 异步编程是一项关键技术,使得能够简单处理多个核心上的阻塞 I/O 和并发操作. 如果需要 I/O 绑定(例如从网络请求数据或访问数据库),则 ...
- Apache搭建http网站服务器入门教程
Apache搭建http网站服务器入门教程 准备工具 一台带有Linux系统的主机,这里使用CentOS 7.1 64位系统 一个备案过的域名,这里使用www.hellopage.cn 一台可以访问网 ...
- Divideing Jewels
Divideing Jewels 时间限制: 1 Sec 内存限制: 128 MB提交: 63 解决: 17[提交][状态] 题目描述 Mary and Rose own a collection ...
- angualr项目引入容联 七陌7mroo
最近项目要求在注册页面增加客服服务浮窗,各种查找资料准备采用7moor来实现.现记录一下实现过程,便于后期查看: 引入7moor浮窗有两种方式: 1.h5方式,这种情况一般是单独打开新页面即可: 直接 ...