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 2n100, 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; 0x, y10, 000 and 1w10, 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 ...
随机推荐
- Quartz实现数据库动态配置定时任务
项目实战 或许实现的方式跟之前的代码有点不一样的 1.定时任务的配置信息 @Configuration public class ScheduleConfigration { @Autowired p ...
- vue 踩坑之组件传值
Vue 报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the pa ...
- 1.ireport基本使用
1. 2.
- LuaLuaMemorySnapshotDump-master
https://codeload.github.com/yaukeywang/LuaMemorySnapshotDump/zip/master
- UIWindow,UINavigationController,UIViewController
- psfstriptable - 从控制台字体中移走嵌入的Uniocde字符表
总览 psfstriptable 字体文件 [输出文件] 描述 psfstriptable 命令从 字体文件 或者标准输入(此时的 字体文件 是单个破折号(-))读取一个可能含有嵌入Unicode字体 ...
- 二、IDS4配置服务
它是根据定义配置服务Config.cs文件来生成客户端和API使用该服务所需的配置数据. 一.IDS4签名服务 1.为项目添加NuGet包. 2.IDS4服务制定的配置Config.cs. using ...
- C++ 从txt文本中读取map
由于存入文本文件的内容都为文本格式,所以在读取内容时需要将文本格式的内容遍历到map内存中,因此在读取时需要将文本进行切分(切分成key和value) 环境gcc #include<iostre ...
- docker:docker的基本了解
1.什么是docker 简单的理解:docker相当于vmvare,容器相当于多个虚拟机,vmvare上可以运行ubantu16.04的虚拟机,也可以运行centos虚拟机,还可以运行redhat虚拟 ...
- MySQL DDL Demo
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11606833.html DDL Demo CREATE TABLE `user` ( `id` ) u ...