CodeForces 2020 Ateneo de Manila University D. Riana and Distribution of Pie 思維題

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:

  1. Person ii begins his turn by choosing a percentage Pi%P_i\% between 0-100.

  2. Person ii then takes Pi%P_i\% of the pie remaining.

  3. Person ii ends his turn by taking Pi%P_i\% of the slices of pie that have already been taken by everyone who went before person ii.

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 NN, the number of people going to the party.

The value NN is guaranteed to be between 11 and 10310^{3}.

1.4. Output

Output contains NN lines.

The iith line of the output must contain the percentage of the pie which the iith 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 10410^{-4} 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:

  1. 100% of the cake is eaten.
  2. 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. 解讀

題意:桌子上有一隻炸雞,它的初始比例爲 100%100\%

  • Person ii 先在 [0,100][0,100] 中選擇一個數字PiP_i,構成比例Pi%P_i\%

  • Person ii 再拿走桌子上剩下的炸雞的 Pi%P_i\%

  • Person ii 最後非常殘忍地依次從每個在他前面拿炸雞的人手中拿走 Pi%P_i\% 他們手中的炸雞。

你以爲這樣就完事了嗎?還有兩個要求

  1. 炸雞必須100%100\% 地被分掉
  2. 分到最多的人和分到最少的人他們手中炸雞比例的差值要最小

輸出的結果與標準答案差值不超過 10410^{-4} 即爲正確。

題解

  • 首先從炸雞必須100%100\% 地被分掉這個條件來考慮。如果每個人選擇的比例Pi%[0,1)P_i\% \in[0, 1),那麼炸雞永遠不會被分完,所以肯定要有一個人的 Pi%=1P_i\% = 1,如果這個人不是第一個人,則會把前面的人手上的炸雞全部搶走,實在過於殘忍,也不滿足要求2,所以讓第一個人先拿走全部的炸雞。

  • 再從要求2來考慮,全部平分的情況下,差值是最小的,那麼要怎麼達到平分的效果呢?我們已經有了 P1%=1P_1\% = 1,我們可以再想到,最後一個人要從前面的所有人手上拿炸雞,那麼最後他手上一定會有 Pn%P_n\% 個炸雞。

有了對第一個人和最後一個人的推斷,那麼考慮只有2個人的情況,P1%=1P_1\% = 1P2%=0.5P_2\% = 0.5,炸雞就被平分了。

再考慮3個人的情況,3個人要平分的話,每個人 1/3,也就是 P3%=1/3P_3\% = 1/3,那麼其實只要前面2個人手上各有 0.5只炸雞,最後炸雞就被平分了。

於是我們就可以推斷,第 ii 個人的分配比例爲

Pi%=1iP_i\% = \frac{1}{i}

保留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]

CSDNhttps://me.csdn.net/qq_41729780

知乎https://zhuanlan.zhihu.com/c_1225417532351741952

公衆號複雜網絡與機器學習

歡迎關注/轉載,有問題歡迎通過郵箱交流。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章