HDU 4946 convex hull

Source: Internet
Author: User

 

Question:

Some vertices are on an infinite graph, and each vertex can control some regions. This region satisfies that the arrival time of this vertex is strictly less than that of other vertices. Find the areas where infinite area can be controlled.

Question:

The control range for low speed is limited.

The infinite area can be controlled only when the maximum speed is reached on the convex hull. The vertical line of any two points is the border, and the left and right sides are controlled in half. The point in the convex hull can only control the limited area.

   

Special Judgment:

Points with the maximum speed and at the same point cannot be controlled in an infinite area, but a convex packet is required for calculation.

The maximum speed is 0 and the infinite area cannot be controlled.

 

For Shared-line convex hull (Graham ),

1. sort by polar coordinate. You need to sort the vertices on the last side in reverse order to add the last side of the common point to the convex hull.

2. sort by level.

 

 

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # include <cmath> # include <vector> # include <utility> # include <stack> # include <queue> # include <map> # include <deque> # define max (X, y) (x)> (y )? (X) :( y) # define min (x, y) (x) <(y )? (X) :( y) # define INF 0x3f3f3fusing namespace STD; const int maxn = 1010; const double EPS = 1e-8; const double Pi = ACOs (-1.0); int Tx, ty, TV, maxv, N, N, CAS; bool Pd [maxn]; int SGN (Double X) {If (FABS (x) <EPS) return 0; if (x <0) Return-1; return 1;} struct point {Double X, Y; int re; point () {} Point (double _ x, double _ y): X (_ x), y (_ y) {} point operator-(const point & B) const {return point (x-B.x, y-B.y );} Point operator + (const point & B) const // vector addition {return point (x + B. x, Y + B. y);} double operator ^ (const point & B) const // Cross Product {return x * B. y-y * B. x;} double operator * (const point & B) const // Point product {return x * B. X + Y * B. y;} bool operator = (const point & B) const {return FABS (B. x-x) <EPS & FABS (B. y-y) <EPS;} bool Operator! = (Const point & B) const {return! (* This) = B);} double norm () // vector modulo {return SQRT (x * x + y * Y);} void transxy (double B) // rotate B radians {double Tx = x, Ty = y; X = TX * Cos (B)-ty * sin (B) counterclockwise around the origin ); y = TX * sin (B) + ty * Cos (B);} void input () // read can only be read in double {scanf ("% lf ", & X, & Y) ;}}; struct line {point S, E; line () {}line (point _ s, point _ e) {S = _ s; E = _ e ;}}; double dist (point a, point B) {return SQRT (a-B) * (a-B ));} // determine bool ONS (point a, Lin E A) {return SGN (. s-A) ^ (. e-a) = 0 & SGN (. x-a.s.x) * (. x-a.e.x) <= 0 & SGN (. y-a.s.y) * (. y-a.e.y) <= 0;} // find the number of the Graham algorithm of the convex hull // point 0 ~ N-1 // return the convex packet result stack [0 ~ Top-1] is the number of a convex packet. // if the number is one or two vertices, the convex packet is one or two vertices. Int stack [maxn], top; point vertex [maxn]; bool graham_cmp (point a, point B) {double TMP = (a-vertex [0]) ^ (B-vertex [0]); If (SGN (TMP)> 0) return 1; if (SGN (TMP) = 0 & SGN (Dist (A, vertex [0])-dist (B, vertex [0]) <= 0) return 1; return 0;} void Graham (int n) {int K = 0; For (INT I = 1; I <n; I ++) if (vertex [K]. y> vertex [I]. y) | (vertex [K]. y = vertex [I]. Y & vertex [K]. x> vertex [I]. x) k = I; Swap (vertex [0], vertex [k]); sort (vertex + 1, vertex + N, graham_cmp); If (n = 1) {Top = 1; stack [0] = 0; return;} If (n = 2) {Top = 2; stack [0] = 0; stack [1] = 1; return ;} int TMP; For (TMP = n-1; TMP> 1 & SGN (vertex [0]-vertex [TMP]) ^ (vertex [0]-vertex [tmp-1]) = 0; TMP --); reverse (vertex + TMP, vertex + n); // stack in reverse order of the last edge [0] = 0; stack [1] = 1; top = 2; for (INT I = 2; I <n; I ++) {While (top> 1 & (vertex [I] = vertex [sta CK [Top-1] | SGN (vertex [stack [Top-1]-vertex [stack [Top-2]) ^ (vertex [I]-vertex [stack [Top-2]) <0) // points on the same line are pushed to the top of the stack only once --; stack [top ++] = I ;}} int main () {// freopen ("1002.in"," r ", stdin); // freopen (" 1002p. out "," W ", stdout); While (scanf (" % d ", & N )! = EOF & N) {memset (PD, 0, sizeof (PD); n = 0; maxv =-1; for (INT I = 0; I <N; I ++) {scanf ("% d", & Tx, & ty, & TV); If (maxv = TV) {vertex [N]. X = TX; vertex [N]. y = ty; vertex [N]. re = I; n ++;} else if (maxv <TV) {maxv = TV; n = 0; vertex [N]. X = TX; vertex [N]. y = ty; vertex [N]. re = I; n ++ ;}} Graham (n); For (INT I = 0; I <top; I ++) Pd [vertex [stack [I]. re] = 1; for (INT I = 0; I <n; I ++) // remove the same point for (Int J = I + 1; j <N; j ++) if (vertex [I] = vertex [J]) {Pd [vertex [I]. re] = 0; Pd [vertex [J]. re] = 0;} printf ("case # % d:", ++ CAS); For (INT I = 0; I <n; I ++) {If (maxv = 0) printf ("0"); else printf ("% d", Pd [I]);} printf ("\ n ");} return 0;}/* 0 0 10 11 12 13 11 1 */
View code

 

Related Keywords:

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.