Sprinkler Nanyang Institute of Technology OJ Question 12

Source: Internet
Author: User
Sprinkler

Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 12

Yesterday I made a greedy algorithm question (see the venue arrangement question ). Consolidate it today.

As shown in, for all circles of R> H/2, the circumference has two intersections with the upper/lower boundary. For example, for the circle on the left of the graph, you can determine L1 = x-√ (R ^ 2-(H/2) ^ 2), R1 = x + √ (R ^ 2-(H/2) ^ 2 ), if L1 is <0, L1 = 0; If r1> W, R1 = W.
Similarly, for the circle on the right, you can determine L2, R2.
In this way, for all given circles that satisfy r> H/2, we can calculate an interval set Si = {[L1, R1], [L2, R2], [L3, r3]... [lN, Rn]}.
The problem to be solved is how to use the minimum range in I to completely cover [0, w].
The next thought is similar to the venue arrangement problem. First, sort all elements in Si in the descending order of the Right Border, then set the current right border rc = 0, Count = 0, then follow the greedy policy:

1) if Si is empty and RC <W, the output cannot be overwritten when the algorithm ends. Otherwise, the first (largest in the right) is used to traverse Si backwards.
2) Delete the first I encountered from Si, where I satisfies L (I) ≤ RC
4) Count ++
3) set rc = R (I). If rc = W, the algorithm ends and count is output; otherwise, GOTO 1 is output)

A similar problem is http://acm.nyist.net/JudgeOnline/problem.php? PID = 6

Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 12

Yesterday I made a greedy algorithm question (see the venue arrangement question ). Consolidate it today.

As shown in, for all circles of R> H/2, the circumference has two intersections with the upper/lower boundary. For example, for the circle on the left of the graph, you can determine L1 = x-√ (R ^ 2-(H/2) ^ 2), R1 = x + √ (R ^ 2-(H/2) ^ 2 ), if L1 is <0, L1 = 0; If r1> W, R1 = W.
Similarly, for the circle on the right, you can determine L2, R2.
In this way, for all given circles that satisfy r> H/2, we can calculate an interval set Si = {[L1, R1], [L2, R2], [L3, r3]... [lN, Rn]}.
The problem to be solved is how to use the minimum range in I to completely cover [0, w].
The next thought is similar to the venue arrangement problem. First, sort all elements in Si in the descending order of the Right Border, then set the current right border rc = 0, Count = 0, then follow the greedy policy:

1) if Si is empty and RC <W, the output cannot be overwritten when the algorithm ends. Otherwise, the first (largest in the right) is used to traverse Si backwards.
2) Delete the first I encountered from Si, where I satisfies L (I) ≤ RC
4) Count ++
3) set rc = R (I). If rc = W, the algorithm ends and count is output; otherwise, GOTO 1 is output)

A similar problem is http://acm.nyist.net/JudgeOnline/problem.php? PID = 6

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.