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, xy, and w, where (xy) is the coordinate of the left-lower corner of a square and w is the length of a side of the square; 0xy10, 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(旋转卡壳)的更多相关文章

  1. UVAL 4728 Squares(旋转卡壳)

    Squares [题目链接]Squares [题目类型]旋转卡壳 &题解: 听着算法名字,感觉挺难,仔细一看之后,发现其实很简单,就是依靠所构成三角行面积来快速的找对踵点,就可以省去很多的复杂 ...

  2. UVALive 4728 Squares (平面最远点对)

    题意:n个平行于坐标轴的正方形,求出最远点对的平方 题解:首先求出凸包,可以证明最远点对一定是凸包上的点对,接着可以证明最远点对(每个点的对踵点)一定只有3*n/2对 接着使用旋转卡壳找到最远点对,但 ...

  3. UVa 1453 - Squares 旋转卡壳求凸包直径

    旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...

  4. uvalive 4728 Squares

    题意:求所有正方形中两点距离最大值的平方值. 思路:旋转卡壳法. 分别用数组和vector存凸包时,旋转卡壳代码有所不同. #include<cstdio> #include<cma ...

  5. LA 4728 (旋转卡壳) Squares

    题意: 求平面上的最远点对距离的平方. 分析: 对于这个数据量枚举肯定是要超时的. 首先这两个点一定是在凸包上的,所以可以枚举凸包上的点,因为凸包上的点要比原来的点会少很多,可最坏情况下的时间复杂度也 ...

  6. UVA 4728 Squares(凸包+旋转卡壳)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...

  7. LA 4728 旋转卡壳算法求凸包的最大直径

    #include<iostream> #include<cstdio> #include<cmath> #include<vector> #includ ...

  8. 1393: Robert Hood 旋转卡壳 凸包

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1393 http://poj.org/problem?id=2187 Beauty Contest ...

  9. POJ 3608 Bridge Across Islands --凸包间距离,旋转卡壳

    题意: 给你两个凸包,求其最短距离. 解法: POJ 我真的是弄不懂了,也不说一声点就是按顺时针给出的,不用调整点顺序. 还是说数据水了,没出乱给点或给逆时针点的数据呢..我直接默认顺时针给的点居然A ...

随机推荐

  1. 攻防世界--crackme

    测试文件:https://adworld.xctf.org.cn/media/task/attachments/088c3bd10de44fa988a3601dc5585da8.exe 1.准备 获取 ...

  2. k3 cloud成本调整单引入单据后,再做出库成本核算。成本调整单列表已审核的单据消失,非已审核的单据还在,这是出库成本核算设置参数的问题吗?

    存货核算时,会将“期末余额调整”类型的的调整单删除后,再重新产生:因此引入后不要再做出库核算,或者引入其它类型的单据.

  3. H5中滚动到底部的事件

    问题:在H5中,我们有这样的需求:例如有列表的时候,滚动到底部时,需要加载更多. 解决方案:可以采用window的滚动事件进行处理 分析:如果滚动是针对整个屏幕而言的(不针对于某个界面小块),那么这个 ...

  4. Centos上Docker的安装及加速

    #环境 :内核的版本必须大于3.10 #安装docker yum install epel-release -y yum install docker-ce ##安装docker-ce #配置文件 d ...

  5. vue,一路走来(3)--数据交互vue-resource

    所有的静态页面布局完成后,最重要的就是数据交互了,简单来说,vue-resource就像jquery里的$.ajax,用来和后台交互数据的.放在created或ready里运行来获取或者更新数据的.不 ...

  6. Java疯狂讲义笔记——内部类

    [定义]内部类:定义在其它类内部的类.外部类:包含内部类的类,也称 宿主类.局部内部类:定义在方法里的内部类. [接口内部类]接口中也可以定义内部类,必须为public static修饰(自动添加), ...

  7. Codecraft-17 and Codeforces Round #391 - C

    题目链接:http://codeforces.com/contest/757/problem/C 题意:给定n个gym和m个Pokemon的类型,然后给你每个gym内的Pokemon未进化之前的类型, ...

  8. python常用魔法函数

    1.__init__(): 所有类的超类object,有一个默认包含pass的__init__()实现,这个函数会在对象初始化的时候调用,我们可以选择实现,也可以选择不实现,一般建议是实现的,不实现对 ...

  9. Djano中static和media文件路径的设置

    对于常用的css.js.image和常用的工具类在django项目中要设置一个全局的路径,对所有的app都可以访问到这个路径下的文件 1在django项目的setting文件中设置对应的static和 ...

  10. mysql 数据库连接状态查询

    查看当前数据库进程 show processlist