Title: http: //acm.hdu.edu.cn/showproblem.php pid = 4637?
Reference from: https: //www.cnblogs.com/javawebsoa/p/3239001.html
#include<bits/stdc++.h> using namespace std; #define pii pair <double, double> #define mp make_pair #define pb push_back #define X first #define Y second const 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) and (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 { return point(t * x, t * y); } } He is, and; 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 (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x); } double dis(const point &a, const point &b) { return sqrt(F(a.x - b.x) + F(a.y - b.y)); } BOOL segSegIntersect ( const Point & A, const Point & B, const Point & L, const Point & R & lt) { // two line segments intersect (irrespective collinear) return Cross (A, B, L) * Cross (A, B, R & lt) < EPS && Cross (L, R & lt, A) * Cross (L, R & lt, B) < EPS; } double intersect(const point &a, const point &b, const point &l, const point &r) {//俩直线求交点的x double ret = a.x; double t = ((a.x - l.x) * (l.y - r.y) - (a.y - l.y) * (l.x - r.x)) / ((a.x - b.x) * (l.y - r.y) - (a.y - b.y) * (l.x - r.x)); return ret + (b.x - a.x) * t; } Vector < Double > VEC; // record the intersection with raindrops Vector <PII> RES; // record is hit each time segment raindrops struct Rain { point o, a, b, c; double r, h; void in() { CIN >> OX Oy >> >> >> R & lt H; /// record only triangular raindrops to A = O, B = O, C = O; a.x -= r; b.x += r; c.y += h; } BOOL Inside ( const Point & P) { // point are raindrops inside (including the boundary) return (DIS (O, P) - EPS <&& R & lt Py - EPS < Oy) || (Cross (C, A, P)> Cross && -EPS (C, B, P) < EPS && Py> Oy + EPS); } void Query1 () { // semicircular cross raindrops find the intersections Point STA = B, D = ED- STA; Double A = D * D; Double B = (BO) * * D 2 ; Double C = (BO) * (BO) -R & lt * R & lt; Double dlt * = the B-B . 4 * a * C; IF (dlt <-EPS) return ; IF (dlt <EPS) dlt = 0 ; // eliminate the negative case dlt zero else = DLT sqrt (DLT); double t=(-B-dlt)/(2*A); TP Point = D + B * T; /// semicircular one-two possible points of intersection into a IF (EPS-tp.x <sta.x && tp.x + EPS> EPS-ed.x && tp.y <Oy) // because it is semi-circular, pay attention to the useless point out the sentence vec.pb (tp.x); t=(-B+dlt)/(2*A); tp=b+d*t; if (tp.x-eps<sta.x&&tp.x+eps>ed.x&&tp.y-eps<o.y) vec.pb(tp.x); } void of query2 () { // triangular cross raindrops find the intersections (not horizontal line segment therein, and since only counted out, does not affect the horizontal) Double X; IF (segSegIntersect (A, C, STA, ED)) { x=intersect(a,c,sta,ed); if(x-eps>ed.x&&x+eps<sta.x) vec.pb(x); } if(segSegIntersect(c,b,sta,ed)){ x=intersect(c,b,sta,ed); if(x-eps>ed.x&&x+eps<sta.x) vec.pb(x); } } void solve() { vec.clear(); query1(); query2(); /// determining start and end points have not within the scope of the current point IF (Inside (STA)) vec.pb (sta.x); IF (Inside (ED)) vec.pb (ed.x); sort (vec.begin (), vec.end ()); int m = UNIQUE (vec.begin (), vec.end ()) - vec.begin (); IF (m> = 2 ) // taking the maximum and minimum of the two points of intersection is to be hit raindrops period end points res.pb (MP (VEC [ 0 ], VEC [M- . 1 ])); } }on one; void init(){ } int main () { int event; cin>>cas; for (int p=1;p<=cas;p++){ cin>>v1>>v2>>v>>t>>x>>n; T=v1*t/(v2-v1)+t; sta.x = x; sta.y = 0 ; ed.x=x-v1*T; ed.y=v*T; years = 0 ; res.clear(); for(int i=0;i<n;i++){ num.in(); num.solve(); } sort(res.begin(), res.end()); double r=ed.x; for (int i=0;i<res.size();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){ years + nothing = [i] .Y- nothing [i] .x; r=res[i].Y; } } printf("Case %d: %.4f\n",p,ans/v1); } return 0; }