Ultraviolet A 920-Sunny Mountains

Source: Internet
Author: User

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 ;}



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.