Question: There are some mountains. In a flat mountain, we will give you the coordinates of each mountain. The sun shines from the right side, and the length and.
Analysis: Computation Geometry and greed. First, sort by coordinates. Then, find the first mountain on the left that is higher than it,
Find the corresponding illumination length and sum it up.
Note: While (scanf ("% d", & T) causes TLE, round (delayed) rollback.
# Include <algorithm> # include <iostream> # include <cstdlib> # include <cstdio> # include <cmath> using namespace STD; typestrudef CT pnode {Double X, Y ;} point; point P [100]; bool CMP (point a, point B) {return. x> B. x;} double dist (point a, point B) {return SQRT (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} int main () {int t, n; while (~ Scanf ("% d", & T) while (t --) {scanf ("% d", & N); For (INT I = 0; I <N; ++ I) scanf ("% lf", & P [I]. x, & P [I]. y); sort (p, p + N, CMP); double sums = 0.0; int last = 0; For (INT I = 1; I <n; ++ I) if (P [I]. y> P [last]. y) {sums + = dist (P [I], p [I-1]) * (p [I]. y-P [last]. y)/(P [I]. y-P [I-1]. y); last = I;} printf ("%. 2lf \ n ", sums);} return 0 ;}