[ACM-ICPC][Asia - Seoul][Farthest Pair] 4728 - Squares@Morris' Blog|PChome Online 人新台
2012-09-22 08:20:32| 人749| 回0 | 上一篇 | 下一篇

[ACM-ICPC][Asia - Seoul][Farthest Pair] 4728 - Squares

0 收藏 0 0 站台

The famous Korean IT company epsfbox{p4728_c.eps} 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 epsfbox{p4728_c.eps}. But, due to the inaccuracy of the sensing devices equipped in the sensors, epsfbox{p4728_c.eps} 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. epsfbox{p4728_c.eps} 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.

epsfbox{p4728.eps}

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$ le$n$ le$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$ le$x, y$ le$10, 000 and 1$ le$w$ le$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, where D 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

要找最, 必做一次凸包

做法是旋卡尺, 不我想我的做法不是的旋卡尺, 不找最的候, 仍然是 O(n)


#include <cstdio>
#include <algorithm>
using namespace std;
typedef struct {
int x, y;
} Pt;
Pt P[500000], H[500000];
bool cmp(Pt a, Pt b) {
if(a.x != b.x)
return a.x < b.x;
return a.y < b.y;
}
int cross(Pt &o, Pt &a, Pt &b) {
return (a.x-o.x)*(b.y-o.y) - (a.y-o.y)*(b.x-o.x);
}
void solve(int n) {
sort(P, P+n, cmp);
int i, j, m = 0, t;
for(i = 0; i < n; i++) {
while(m >= 2 && cross(H[m-2], H[m-1], P[i]) <= 0)
m--;
H[m++] = P[i];
}
for(i = n-1, t = m+1; i >= 0; i--) {
while(m >= t && cross(H[m-2], H[m-1], P[i]) <= 0)
m--;
H[m++] = P[i];
}
m--;
int ans = 0, tmp, now;
for(i = 0, j= 1; i < m; i++) {
while(1) {
now = (H[i].x-H[j].x)*(H[i].x-H[j].x)+
(H[i].y-H[j].y)*(H[i].y-H[j].y);
j++;
if(j >= m) j = 0;
tmp = (H[i].x-H[j].x)*(H[i].x-H[j].x)+
(H[i].y-H[j].y)*(H[i].y-H[j].y);
if(tmp < now) {
j--;
if(j < 0) j = m-1;
break;
}
}
if(now > ans) ans = now;
}
printf("%d\n", ans);
}
int main() {
int t, x, y, w;
scanf("%d", &t);
while(t--) {
int n, m = 0;
scanf("%d", &n);
while(n--) {
scanf("%d %d %d", &x, &y, &w);
P[m].x = x, P[m++].y = y;
P[m].x = x+w, P[m++].y = y;
P[m].x = x, P[m++].y = y+w;
P[m].x = x+w, P[m++].y = y+w;
}
solve(m);
}
return 0;
}
 


台: Morris
人(749) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分:UVA |
此分下一篇:[ACM-ICPC][Asia - Seoul][人][模解] 4727 - Jump
此分上一篇:[ACM-ICPC][Asia - Seoul] 4723 - Ducci Sequence

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86