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