Uvalive 4728 Squares

Source: Internet
Author: User

Test instructions: The square value of the maximum value of two points in all squares.

Idea: Rotating Jam method.

When you use arrays and vectors to store convex packets separately, the rotation jam code is different.

1#include <cstdio>2#include <cmath>3#include <cstring>4#include <algorithm>5#include <iostream>6#include <memory.h>7#include <cstdlib>8#include <vector>9 #defineCLC (A, B) memset (A,b,sizeof (a))Ten #defineLL Long Long int One #defineUp (I,x,y) for (i=x;i<=y;i++) A #defineW (a) while (a) - using namespacestd; - Const Doubleinf=0x3f3f3f3f; the Const intN =4010; - Const DoubleEPS =5*1e- -; - Const DoublePI = ACOs (-1.0); - using namespacestd; +  - struct Point + { A     intx, y; atPoint (intx=0,inty=0): X (x), Y (y) {} - }; -  - typedef point Vector; -  -Vectoroperator- (Constpoint& A,Constpoint&B) in { -     returnVector (a.x-b.x, a.y-b.y); to } +  - intCross (Constvector& A,Constvector&B) the { *     returna.x*b.y-a.y*b.x; $ }Panax Notoginseng  - intDot (Constvector& A,Constvector&B) the { +     returna.x*b.x + a.y*b.y; A } the  + intDist2 (Constpoint& A,Constpoint&B) - { $     return(a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y); $ } -  - BOOL operator< (Constpoint& P1,Constpoint&p2) the { -     returnp1.x < p2.x | | (p1.x = = p2.x && P1.y <p2.y);Wuyi } the  - BOOL operator== (Constpoint& P1,Constpoint&p2) Wu { -     returnp1.x = = p2.x && P1.y = =p2.y; About } $  - //Point set Convex package - //If you do not want to have an input point on the side of the convex hull, change the two <= to < - //Note: The input point assembly is modified AVector<point> Convexhull (vector<point>&p) + { the     //preprocessing, removing duplicate points - sort (P.begin (), P.end ()); $ p.erase (Unique (P.begin (), P.end ()), P.end ()); the  the     intn =p.size (); the     intm =0; theVector<point> CH (n+1); -      for(inti =0; I < n; i++) in     { the          while(M >1&& Cross (ch[m-1]-ch[m-2], p[i]-ch[m-2]) <=0) m--; thech[m++] =P[i]; About     } the     intK =m; the      for(inti = n2; I >=0; i--) the     { +          while(M > K && Cross (ch[m-1]-ch[m-2], p[i]-ch[m-2]) <=0) m--; -ch[m++] =P[i]; the     }Bayi     if(N >1) m--; the ch.resize (m); the     returnch; - } -  the //returns the square of the point set diameter the intDiameter2 (vector<point>&points) the { theVector<point> p =Convexhull (points); -     intn =p.size (); the     if(n = =1)return 0; the     if(n = =2)returnDist2 (p[0], p[1]); theP.push_back (p[0]);//lest the mold be taken94     intAns =0; the      for(intU =0, V =1; U < n; u++) the     { the         //a straight line to the side p[u]-p[u+1]98          for(;;) About         { -             //Stop rotation when area (P[u], p[u+1 [], p[v+1]) <= area (P[u], p[u+1], p[v])101             //( P[u+1]-p[u], P[v+1]-p[u])-Cross (P[u+1]-p[u], P[v]-p[u]) <= 0102             //According to Cross (A, b)-Cross (A,C) = Cross (a,b-c)103             //Simplification cross (P[u+1]-p[u], p[v+1]-p[v]) <= 0104             intdiff = Cross (p[u+1]-p[u], p[v+1]-p[v]); the             if(diff <=0)106             {107ans = max (ans, Dist2 (P[u], p[v]));//U and V are the heel points108                 if(diff = =0) ans = max (ans, Dist2 (P[u], p[v+1]));//diff = 0 o'clock U and v+1 are also the heel point109                  Break; the             }111v = (v +1) %N; the         }113     } the     returnans; the } the 117 intMain ()118 {119     intT; -scanf"%d", &T);121      while(t--)122     {123         intN;124scanf"%d", &n); theVector<point>points;126          for(inti =0; I < n; i++)127         { -             intx, Y, W;129scanf"%d%d%d", &x, &y, &W); the Points.push_back (Point (x, y));131Points.push_back (Point (x+W, y)); thePoints.push_back (Point (X, y+W));133Points.push_back (Point (X+w, y+W));134         }135printf"%d\n", Diameter2 (points));136     }137     return 0;138}
View Code

Uvalive 4728 Squares

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.