文章目錄
1. 題目描述
1.1. Limit
Time Limit: 1 second
Memory Limit: 256 megabytes
1.2. Problem Description
Riana baked a round pie in preparation for her birthday party. After baking the pie, she thought that it would be boring to simply give the pie evenly across everyone attending her party. After some thought, she came up with the idea of using the pie in a game for the party goers.
In her game, each person attending the party will each take only one turn.
One full turn goes like this:
-
Person begins his turn by choosing a percentage between 0-100.
-
Person then takes of the pie remaining.
-
Person ends his turn by taking of the slices of pie that have already been taken by everyone who went before person .
For example, if four people Mathil, Quin, Octavian, and Velyna attend the party:
-
In the first turn, Mathil starts by choosing 30%.
-
He then takes 30% of the remaining pie which has not been touched, meaning Mathil takes 30%.
- Mathil has 30% of the pie.
- The pie is now 70% of its original size.
-
In the second turnn Quin chooses 20%.
-
Quin then takes 20% of what’s left of the pie, which is 14% of the pie’s original size.
-
Next, Quin takes 20% of Mathil’s slice, which is 6% of the pie’s original size.
- Mathil now only has 24% of the pie, while Quin has (14%+6%) 20% of the pie’s original size.
- The pie is now 56% of its original size.
-
In the third turn, Octavian comes in and chooses 10%.
-
Octavian take 10% of the what’s left of the pie, which is 5.6% of the pie’s original size.
-
He then takes 10% of Mathil’s remaining 24% and Quin’s 20%
- Mathil now only has 21.6% of the pie’s original size.
- Quin now only has 18% of the pie’s original size.
- Octavian has 10% of the pie’s original size.
- The pie is now 50.4% of its original size.
-
In the fourth and final turn, Velyna comes in and chooses 50%.
-
Velyna takes 50% of the what’s left of the pie, which is 25.2% of the pie’s original size.
-
She then takes 50% of Mathil’s remaining 21.6%, Quin’s remaining 18%, and Octavian’s 10%.
- Mathil now only has 10.8% of the pie’s original size.
- Quin now only has 9% of the pie’s original size.
- Octavian now only has 5% of the pie’s original size.
- Velyna has 50% of the pie’s original size.
- The pie is now 25.2% of its original size.
But wait! this is wrong! Riana’s household has a strict ‘no leftovers’ policy, so she wants 100% of the pie to get eaten!
Riana is also an advocate of equality, so she wants to distribute the pie slices such that the difference between the biggest slice and the smallest slice is minimized.
However, Riana is also secretly lazy, so she enlisted the help of her friend, you! Help her figure out the optimal percentage each person should take.
1.3. Input
The input will contain one line containing a single integer , the number of people going to the party.
The value is guaranteed to be between and .
1.4. Output
Output contains lines.
The th line of the output must contain the percentage of the pie which the th person to take slices should take. (The first person’s percentage should be on the first line, the second should be on the second line, the third should be on the third line, etc.)
Answers will be accepted if they are within away from the correct answer.
1.5. Sample Input
1
1.6. Sample Output
100.0000
1.7. Note
In the sample test case, since the first person is the only person in the party (quite sad), he takes the whole cake.
This satisfies the two conditions that Riana wanted to satisfy:
- 100% of the cake is eaten.
- The difference between the Maximum and the Minimum is minimized. (The difference is 0.)
1.8. Source
CodeForces 102556 D. Riana and Distribution of Pie
2. 解讀
題意:桌子上有一隻炸雞,它的初始比例爲 。
-
Person 先在 中選擇一個數字,構成比例 。
-
Person 再拿走桌子上剩下的炸雞的 。
-
Person 最後非常殘忍地依次從每個在他前面拿炸雞的人手中拿走 他們手中的炸雞。
你以爲這樣就完事了嗎?還有兩個要求
- 炸雞必須 地被分掉
- 分到最多的人和分到最少的人他們手中炸雞比例的差值要最小
輸出的結果與標準答案差值不超過 即爲正確。
題解:
-
首先從炸雞必須 地被分掉這個條件來考慮。如果每個人選擇的比例,那麼炸雞永遠不會被分完,所以肯定要有一個人的 ,如果這個人不是第一個人,則會把前面的人手上的炸雞全部搶走,實在過於殘忍,也不滿足
要求2
,所以讓第一個人先拿走全部的炸雞。 -
再從
要求2
來考慮,全部平分的情況下,差值是最小的,那麼要怎麼達到平分的效果呢?我們已經有了 ,我們可以再想到,最後一個人要從前面的所有人手上拿炸雞,那麼最後他手上一定會有 個炸雞。
有了對第一個人和最後一個人的推斷,那麼考慮只有2個人
的情況,,,炸雞就被平分了。
再考慮3個人
的情況,3個人要平分的話,每個人 1/3
,也就是 ,那麼其實只要前面2個人
手上各有 0.5
只炸雞,最後炸雞就被平分了。
於是我們就可以推斷,第 個人的分配比例爲
保留5位小數即可。
3. 代碼
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
printf("%.5lf\n", (1.0 / i) * 100);
}
}
聯繫郵箱:[email protected]
CSDN:https://me.csdn.net/qq_41729780
知乎:https://zhuanlan.zhihu.com/c_1225417532351741952
公衆號:複雜網絡與機器學習
歡迎關注/轉載,有問題歡迎通過郵箱交流。