HDU 4946 Area of Mushroom convex hull, hdu4946

Source: Internet
Author: User

HDU 4946 Area of Mushroom convex hull, hdu4946

Link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 4946

There are n people. In the position (xi, yi), the speed is vi. If one person can come to that point before all others, this point is contracted by this person. The number of contracted (fish ponds) area is infinite.

Idea: Find out the maximum speed. Only the person with the maximum speed can contract an infinite area (because the high-speed person will catch up with the low-speed person sooner or later ). The boundary between two people is the vertical line of their coordinates, which proves that when a convex bag is formed, the contracted area must be limited. Therefore, the person (including the side) on the convex hull can contract an infinite area. Note: because the requirements in the question must be strictly less than the time when other people arrive to contract, if there are two people with high emphasis on speed, neither of them can be contracted, however, when calculating convex packets, they need to be included because they may not be contracted by others because of their existence.

Code:

# Include <algorithm> # include <cmath> # include <cstdio> # include <cstdlib> # include <cstring> # include <ctime> # include <ctype. h> # include <iostream> # include <map> # include <queue> # include <set> # include <stack> # include <string> # include <vector> # define eps 1e-10 # define INF 0x7fffffff # define maxn 10005 # define PI acos (-1.0) # define seed 31 // 131,1313 typedef long LL; typedef unsigned long ULL; using name Space std; int x [505], y [505], v [505], vis [505]; int cmp (double x) {if (fabs (x) <eps) return 0; if (x> 0) return 1; return-1;} inline double sqr (double x) {return x * x;} struct point // point {double x, y; int pos; int o; point () {} point (double a, double B): x (a), y (B) {} void input () {scanf ("% lf", & x, & y);} friend point operator + (const point & a, const point & B) {return point (. x + B. x,. y + B. y);} friend point ope Rator-(const point & a, const point & B) {return point (. x-b.x,. y-b.y);} friend bool operator = (const point & a, const point & B) {return cmp (. x-b.x) = 0 & cmp (. y-b.y) = 0;} friend point operator * (const point & a, const double & B) {return point (. x * B,. y * B);} friend point operator * (const double & a, const point & B) {return point (a * B. x, a * B. y);} friend point operator/(const point & a, const d Ouble & B) {return point (. x/B,. y/B);} double norm () {return sqrt (sqr (x) + sqr (y);} // void out () from the origin () const {printf ("%. 2f %. 2f ", x, y) ;}} p [505]; double det (const point & a, const point & B) {return. x * B. y-a.y * B. x ;}// double dot (const point & a, const point & B) {return. x * B. x +. y * B. y ;}// point multiplied by double dist (const point & a, const point & B) {return (a-B ). norm ();} // distance from point rotate_point (const point & p, dou Ble A) {double tx = p. x, ty = p. y; return point (tx * cos (A)-ty * sin (A), tx * sin (A) + ty * cos (A);} // rotate, A is A radian struct polygon_convex {vector <point> P; polygon_convex (int size = 0) {P. resize (size) ;}} p_c; bool comp_less (const point & a, const point & B) {return cmp (. x-b.x) <0 | cmp (. x-b.x) = 0 & cmp (. y-b.y) <0;} polygon_convex convex_hull (vector <point> a) {polygon_convex res (2 *. size () + 5); sort (. begin (),. end (), comp_l Ess);. erase (unique (. begin (),. end (),. end (); int m = 0; for (int I = 0; I <. size (); I ++) {while (m> 1 & cmp (det (res. P [M-1]-res. [m-2], a [I]-res. P [m-2]) <0) m --; res. P [m ++] = a [I];} int k = m; for (int I = int (. size ()-2; I> = 0; I --) {while (m> k & cmp (det (res. P [M-1]-res. [m-2], a [I]-res. P [m-2]) <0) m --; res. P [m ++] = a [I];} res. p. resize (m); if (. size ()> 1) res. p. resize (m-1); return res;} bool cmp3 (point a, poi Nt B) {return. x <B. x | (. x = B. x) & (. y <B. y);} int main () {int T, tt = 0; while (scanf ("% d", & T) {tt ++; vector <point> pp; pp. clear (); memset (vis, 0, sizeof (vis); if (T = 0) break; int pos =-1; int max_v = 0; for (int I = 1; I <= T; I ++) {scanf ("% d", & x [I], & y [I], & v [I]); if (v [I]> max_v) max_v = v [I];} int top = 0; for (int I = 1; I <= T; I ++) {if (v [I] = max_v) {p [top]. x = (double) x [I]; p [top]. y = (double) y [I]; p [top]. pos = I; p [top]. o = 0; top ++ ;}} printf ("Case # % d:", tt); if (max_v = 0) {for (int I = 1; I <= T; I ++) printf ("0"); printf ("\ n"); continue;} sort (p, p + top, cmp3 ); for (int I = 0; I <top; I ++) {if (I <top-1 & (p [I]. x) = (p [I + 1]. x) & (p [I]. y) = (p [I + 1]. y) | (I> 0 & (p [I]. x) = (p [I-1]. x) & (p [I]. y) = (p [I-1]. y) p [I]. o = 1;} pp. push_back (p [0]); for (int I = 1; I <top; I ++) {if (p [I]. x! = P [I-1]. x | p [I]. y! = P [I-1]. y) pp. push_back (p [I]);} if (pp. size () <= 3) {for (int I = 0; I <pp. size (); I ++) if (pp [I]. o = 0) vis [pp [I]. pos] = 1;} else {polygon_convex ans = convex_hull (pp); for (int I = 0; I <ans. p. size (); I ++) {if (ans. P [I]. o = 0) vis [ans. P [I]. pos] = 1 ;}}for (int I = 1; I <= T; I ++) printf ("% d", vis [I]); printf ("\ n");} return 0 ;}




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.