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();
}

最新文章

  1. C#之反射
  2. 【JS】数字转大写中文
  3. Ptex源码学习笔记-2
  4. java基础十一[远程部署的RMI](阅读Head First Java记录)
  5. &lt;转&gt;Npoi导入导出Excel操作&lt;载&gt;
  6. iOS开发主要参考文档(转载)
  7. 关于SWT/JFace的API文档
  8. BI任务列表
  9. Oracle EBS-SQL (WIP-15):检查车间任务物料未发数量与现有量对照.sql
  10. 201521123018 《Java程序设计》第1周学习总结
  11. 【ODPS】TableTunnel单线程简单下载事例
  12. Codeforces #Round 406(Div.2)
  13. Linux 下的JDK环境的搭建
  14. 调试 - Chrome调试
  15. ESP8266清理flash学习记录
  16. Docker Doc之一:小白入门
  17. 仙人掌 &amp;&amp; 圆方树 &amp;&amp; 虚树 总结
  18. 转载——githup的提交
  19. vue入门:axios的应用及拦截封装
  20. CreateDialog 注意事项

热门文章

  1. 高阶函数map,filter,reduce的用法
  2. XML处理指令
  3. XMPP即时通讯协议使用(六)——开发Openfire聊天记录插件
  4. Tomcat的用途
  5. 树的计数 Pr&#252;fer编码与Cayley公式 学习笔记
  6. 2019CCPC网络预选赛 1004 path 最短路
  7. HTML基础:用表单写一个简易登录页面
  8. spring cloud学习笔记四 熔断器Hystrix
  9. GSL--GNU Scientific Library 小记
  10. Java Web学习总结(9)学习总结-JSTL