LA 4728 Squares

Source: Internet
Author: User

Original question:
The famous Korean IT company NHN plans to make a digital map of the Earth with help for wireless sensors which spread out I N Rough terrains. Each sensor sends a geographical data to NHN. But, due to the inaccuracy of the sensing devices equipped in the sensors, and NHN only knows a square and which each GE Ographical data happens. Thus a geographical data can is any point in a square region. You is 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 are defined as the maximum (Euclidean) distance among pairs of the points in th E set. The diameter is used as a measurement to estimate the geographical size of the set. NHN 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 DIA M-
Eter for the chosen points is maximized. The sides of the squares is parallel to x-axis or y-axis, and the squares could have different sizes, intersect all other , and share the same corners. For example, if there was six squares as in the "the", then the largest diameter is defined as the distance Between corner points of squares S 1 and
S 4.
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 Cho Sen from all square, and to output D 2, i.e., the squared value of D.
Input
Your program was 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 all test case contains an integer, N, the
Number of squares, where 2≤n≤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 are the length of a side
of the Square; 0≤x,y≤10,000 and 1≤w≤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 D 2, where D was the largest diameter of the points when a point is chosen
From each square.
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

English:
give you n squares so you find out the square of the farthest value of all the points that make up the square vertices.

#include <bits/stdc++.h> using namespace std;

const double eps=1e-6;
    struct point {double x, y;
Point (Double x=0,double y=0): X (x), Y (y) {}};

Point ps[400005],chs[400005];

#define Vector Point Double sq_dist (point A,point B) {return (b.x-a.x) * (b.x-a.x) + (B.Y-A.Y) * (B.Y-A.Y);} BOOL operator < (const point &a,const Point &b)//sorted by x coordinates from small to large, if X is the same, then follow y from small to large {return a.x<b.x| |
(A.X==B.X&AMP;&AMP;A.Y&LT;B.Y); Vector operator + (vector a,vector B) {return vector (A.X+B.X,A.Y+B.Y);} Sit punctuation Add vector operator-(vector a,vector B) {return vector (A.X-B.X,A.Y-B.Y);}
    Subtract int dcmp (double x) {if (Fabs (x) <eps) return 0;
else return x<0?-1:1;


} Double Cross (Vector a,vector B) {return a.x*b.y-a.y*b.x;}
    The int convexhull (point *p,int n,point *ch)//p is all points, n the number of all points, the point in ch which records the convex hull, and returns the number of convex packets {sort (p,p+n);
    int m=0;
       for (int i=0;i<n;i++) {while (M>1&&cross (Ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--; Ch[m++]=p[i];
    } int k=m; 
        for (int i=n-2;i>=0;i--) {while (M>k&&cross (Ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--;
    Ch[m++]=p[i];
    } if (n>1) m--;
return m;
    } double rotating_calipers (point *ch,int N) {int q=1;
    Double ans=0;
    CH[N]=CH[0]; for (int p=0;p<n;p++) {When (Cross (vector (ch[q+1]-ch[p+1]), Vector (ch[p]-ch[p+1)) >cross (Vector (ch[q]-ch[
        P+1]), Vector (ch[p]-ch[p+1])) q= (q+1)%n;
    Ans=max (Ans,max (Sq_dist (ch[p],ch[q)), Sq_dist (ch[p+1],ch[q+1]));
} return ans;
    } int main () {Ios::sync_with_stdio (false);
    int n,t;
    cin>>t;
        while (t--) {cin>>n;
        Double x,y,w;
        int ind=0;
            for (int i=0;i<n;i++) {cin>>x>>y>>w;
            Ps[ind].x=x,ps[ind].y=y;
            ind++;
            Ps[ind].x=x,ps[ind].y=y+w;
            ind++; ps[ind].x=x+w,ps[ind].y=Y
            ind++;
            Ps[ind].x=x+w,ps[ind].y=y+w;
        ind++;
        } int M=convexhull (PS,IND,CHS);
        Double Ans=rotating_calipers (chs,m);
    cout<< (int) ans<<endl;
} return 0;






















 }

Answer:

The bare rotation Jam example, pay attention to the output result when cast to int type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.