No.68 A Common Stick-Cutting Problem (2)
タグ : / 解いたユーザー数 110
作問者 :
LayCurse
Problem Statement
Yuki has \(N\) sticks, and the length of the \(i\)-th stick is \(L_i\).
The sticks can be cut freely (in the direction that divides their length), but they cannot be joined together.
Yuki wants to make sticks of the same length, and is curious about how long they can be for a given number of sticks.
Write a program that, for making \(K_1, K_2,\ldots,K_Q\) sticks of the same length, finds the maximum possible length of the sticks in each case.
Input
\(N\) \(L_1\ L_2\ \cdots\ L_N\) \(Q\) \(K_1\ K_2\ \cdots\ K_Q \)
\(1 \leq N \leq 100000 = 10^5\)
\(1 \leq L_i \leq 1000000000 = 10^9\)
\(1 \leq Q \leq 100000 = 10^5\)
\(1 \leq K_i \leq 500000 = 5 \times 10^5\)
Output
On the $i$-th line, output the maximum length achievable when making $K_i$ sticks of the same length.
Your answer is considered correct if the absolute error or the relative error is at most $10^{-9}$.
Sample
Sample 1
Input
2 10 20 2 3 4
Output
10.00 6.666666666666667
By cutting the stick of length \(20\) into exactly \(2\) equal parts, you get \(3\) sticks of length \(10\).
Also, by cutting the stick of length \(20\) into \(3\) equal parts, and cutting the stick of length \(10\) so that only a length of \(20/3\) remains and discarding the rest, you get \(4\) sticks of length \(20/3\).
Sample 2
Input
5 99 88 77 66 55 5 1 10 100 1000 100000
Output
99 33 3.807692307692307 0.384279475982533 0.003849923001540
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。