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

  1. 2
  2. 3
  3. 0 0 1
  4. 1 0 2
  5. 0 0 1
  6. 6
  7. 2 1 2
  8. 1 4 2
  9. 3 2 3
  10. 4 4 4
  11. 6 5 1
  12. 5 1 3

Sample Output

  1. 13
  2. 85

求出矩阵那些点中,最远的两个点。

那么先求出凸包,然后再用旋转卡壳来弄出最大。

刚刚学卡壳的一到题。

WA在了设置初始对踵点,不可把对踵点设为第一个点,要设成第二个点。

这里我不太懂。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = ;
  4. int n , tot ;
  5. struct Point {
  6. int x , y ;
  7. Point(){};
  8. Point(int a , int b ){x=a,y=b;}
  9. bool operator < ( const Point &a ) const {
  10. if( x != a.x )return x < a.x ;
  11. else return y < a.y ;
  12. }
  13. }p[N<<],ch[N<<];
  14.  
  15. inline int Cross( Point a , Point b ) { return a.x*b.y-a.y*b.x ; }
  16. inline int dis( Point a , Point b ) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
  17. Point operator - ( Point a , Point b ) { return Point(a.x-b.x,a.y-b.y); }
  18. int ConvexHull( Point* p , int n , Point* ch ){
  19.  
  20. int m = ;
  21. sort( p , p + n );
  22. for( int i = ; i < n ; ++i ) {
  23. while( m > && Cross( ch[m-]-ch[m-] , p[i]-ch[m-] ) <= ) m--;
  24. ch[m++] = p[i];
  25. }
  26. int k = m ;
  27. for( int i = n- ; i >= ; --i ){
  28. while( m > k && Cross(ch[m-]-ch[m-],p[i]-ch[m-]) <= ) m--;
  29. ch[m++] = p[i];
  30. }
  31. if( n > ) m--;
  32. return m ;
  33. }
  34.  
  35. int Rotating_Calipers( Point* poly , int n ) {
  36.  
  37. int j = , ans = ;
  38. poly[n] = poly[] ;
  39. for( int i = ; i < n ; ++i ) {
  40. while( fabs( Cross(poly[i+]-poly[i],poly[j]-poly[i]) ) < fabs( Cross(poly[i+]-poly[i],poly[j+]-poly[i]))) j=(j+)%n ;
  41. ans = max( ans , max( dis(poly[i],poly[j]) , dis(poly[i+] ,poly[j])));
  42. }
  43. return ans ;
  44. }
  45.  
  46. void Run() {
  47. int x , y , w ;
  48. scanf("%d",&n);
  49. tot = ;
  50. for( int i = ; i < n ; ++i ) {
  51. scanf("%d%d%d",&x,&y,&w);
  52. p[tot++]=Point(x,y);
  53. p[tot++]=Point(x+w,y);
  54. p[tot++]=Point(x+w,y+w);
  55. p[tot++]=Point(x,y+w);
  56. }
  57. int m = ConvexHull( p , tot , ch );
  58. printf("%d\n",Rotating_Calipers(ch,m));
  59. }
  60.  
  61. int main(){
  62. int _ ; scanf("%d",&_);
  63. while(_--) Run();
  64. }

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. spring(一):spring的基础以及组件

    spring简介 spring是一种开源轻量级框架,是为了解决企业应用程序复杂性而创建的 spring是企业应用开发的“一站式”框架,致力于为javaEE应用的各层(表现层.业务层.持久层)开发提供解 ...

  2. elasticsearch 基础 —— 处理冲突及乐观并发控制

    处理冲突 当我们使用 index API 更新文档 ,可以一次性读取原始文档,做我们的修改,然后重新索引 整个文档 . 最近的索引请求将获胜:无论最后哪一个文档被索引,都将被唯一存储在 Elastic ...

  3. repquota - 文件系统配额的汇总

    SYNOPSIS(总览) repquota [ -vugs ] filesystem... repquota [ -avugs ] DESCRIPTION(描述) repquota 显示与配额文件相关 ...

  4. smbd - 向客户提供SMB/CIFS服务的服务器

    总览 SYNOPSIS smbd [-D] [-F] [-S] [-i] [-h] [-V] [-b] [-d <debug level>] [-l <log directory&g ...

  5. 转载:PhpExcel使用方法

    下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...

  6. HTML基础 内联样式改进 三毛语录

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. Elastic Search快速入门

    https://blog.csdn.net/weixin_42633131/article/details/82902812 通过这个篇文章可以快速入门,快速搭建一个elastic search de ...

  8. 【串线篇】spring boot配置文件大全【下】

    一.配置文件占位符 1.1.随机数 ${random.value}.${random.int}.${random.long} ${random.int(10)}.${random.int[1024,6 ...

  9. 前端每日实战:66# 视频演示如何用纯 CSS 创作一台咖啡机

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/rKPLMW 可交互视频 此视频是可 ...

  10. hive之视图和索引

    一.视图 1.视图定义 视图其实是一个虚表,视图可以允许保存一个查询,并像对待表一样对这个查询进行操作,视图是一个逻辑结构,并不会存储数据. 2.视图的创建 通过创建视图来限制数据访问可以用来保护信息 ...