HDU 4637 Rain on your Fat brother

Source: Internet
Author: User

Question:

It is easy to understand.

 


Practice:

We can regard the raindrops as motionless, and then maze (the person in this question) is moving toward the top left, and calculate the farthest point that maze can run, the next step is to find the time when the line segment composed of the start and end points will be handed over to each raindrops. Note that the question is that each raindrops may be intersecting, So we calculate the intersection interval for each raindrops, merge These intervals and calculate the answer.

 


Note:

1. maze may be in the raindrops at the beginning.

2. maze was caught up with some raindrops. (There is no such data)

3. when the two line segments are in the same line, that is, the side on the right of the triangle is in line with the maze line segment. In this case, we also need to subdivide the line, but I have not determined whether the line is AC, indicating that there is no such data, but we need to consider the problem. (There is no such data)

 


I know that the AC should not be far away. After all, it is not a problem. I did not write the third case in my code.

 


 

# Include <cstdio> # include <cstring> # include <cmath> # include <algorithm> # include <vector> using namespace std; # define pii pair <double, double> # define mp make_pair # define pb push_back # define X first # define Y secondconst double eps = 1e-8; int dcmp (double x) {if (fabs (x) <eps) return 0; return x> eps? 1:-1 ;}struct point {double x, y; point () {}point (double x, double y): x (x), y (y) {} double operator * (const point & t) const {return x * t. x + y * t. y;} point operator-(const point & t) const {return point (x-t. x, y-t. y);} point operator + (const point & t) const {return point (x + t. x, y + t. y);} point operator * (const double & t) const {// note that the point multiplication return point (t * x, t * y);} s, e; double v1, v2, v, t, x, T; double ans; int n; inline double F (double x) {return x * x ;} double cross (const point & o, const point & a, const point & B) {return (. x-o. x) * (B. y-o. y)-(. y-o. y) * (B. x-o. x);} double dis (const point & a, const point & B) {return sqrt (F (. x-B. x) + F (. y-B. y);} bool segintersect (const point & a, const point & B, const point & l, const point & r) {// intersection of two line segments (not considering collinearity) return cross (a, B, l) * cross (a, B, r) <eps & cross (l, r, a) * cross (l, r, B) <eps;} double intersect (const point & a, const point & B, const point & l, const point & r) {// x double ret =. x; double t = (. x-l. x) * (l. y-r. y)-(. y-l. y) * (l. x-r. x)/(. x-B. x) * (l. y-r. y)-(. y-B. y) * (l. x-r. x); return ret + (B. x-. x) * t;} vector <double> vec; // record the intersection of the raindrops vector <pii> res; // record the struct rain {point o, a, B, c; double r, h;/* Three vertex numbers of the raindrops triangle * c */_ \ * a B */void in () {scanf ("% lf", & o. x, & o. y, & r, & h); a = o, B = o, c = o;. x-= r; B. x + = r; c. y + = h;} bool inside (const point & p) {// indicates whether the point is in the raindrops (including the border) return (dis (o, p) -eps <r & p. y-eps <o. y) | (cross (c, a, p)>-eps & cross (c, B, p) <eps & p. y> o. y + eps);} void intersectC () {// calculates the intersection point B = s, d = e-s; double A = d * d; double B = (B-o) * d * 2; double C = (B-o) * (B-o)-r * r; double dlt = B * B-4 * A * C; if (dlt <-eps) return; if (dlt <eps) dlt = 0; // else dlt = sqrt (dlt); double t = (-B-dlt)/(2 * A) when the dlt negative number is eliminated ); point tp = B + d * t; if (tp. x-eps <s. x & tp. x + eps> e. x & tp. y-eps <o. y) // because it is a semi-circle, pay attention to the useless points to determine vec. pb (tp. x); t = (-B + dlt)/(2 * A); tp = B + d * t; if (tp. x-eps <s. x & tp. x + eps> e. x & tp. y-eps <o. y) vec. pb (tp. x);} void intersectT () {// intersection of the triangle with the raindrops (horizontal line segments are not included in this) double x; if (segSegIntersect (a, c, s, e) {x = intersect (a, c, s, e); if (x-eps> e. x & x + eps <s. x) vec. pb (x);} if (segSegIntersect (c, B, s, e) {x = intersect (c, B, s, e ); if (x-eps> e. x & x + eps <s. x) vec. pb (x) ;}} void gao () {vec. clear (); intersectC (); intersectT (); if (inside (s) vec. pb (s. x); if (inside (e) vec. pb (e. x); sort (vec. begin (), vec. end (); int cnt = unique (vec. begin (), vec. end ()-vec. begin (); if (cnt> = 2) // the two largest and smallest intersections are res at the two ends of the time period hit by raindrops. pb (mp (vec [0], vec [cnt-1]) ;}} p; int main () {int I, j, cas; scanf ("% d", & cas); for (int ca = 1; ca <= cas; ca ++) {scanf ("% lf % d", & v1, & v2, & v, & t, & x, & n ); T = v1 * t/(v2-v1) + t; s. x = x; s. y = 0; e. x = x-v1 * T; e. y = v * T; ans = 0; res. clear (); for (I = 0; I <n; I ++) {p. in (); p. gao ();} // calculate the answer sort (res. begin (), res. end (); double r = e. x; int SZ = res. size (); for (I = 0; I <SZ; I ++) {if (res [I]. x-eps <r & r-eps <res [I]. y) {ans + = res [I]. y-r; r = res [I]. y;} else if (r-eps <res [I]. x) {ans + = res [I]. y-res [I]. x; r = res [I]. Y ;}} printf ("Case % d: %. 4f \ n ", ca, ans/v1);} 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.