M - Marbles Lucky Distribution 补提记录
Juan have N red marbles, M blue marbles, and K bottles. He will put a certain number of marbles on each of the K bottles such that no bottle remains empty and every marble is inside a bottle.
Andres is a Santa Fe fan, so he will pick one bottle at random with an uniform distribution, then he will pick a marble inside of it at random with an uniform distribution, with the hope is a red marble. As Juan is a Millonarios fan, he wants to distribute the marbles in the bottles such that the probability of Andres picking a blue marble is maximized. Juan has a busy life, therefore he needs your help to determine the best arrangement for the marbles and the probability of Andres getting a blue marble.
Input The input consist of three integers separated by spaces, N M and K (1?≤?N,?M,?K?≤?109) - the number of red marbles, blue marbles and bottles respectively.
Output Print the probability of Bob getting a blue marble such that the marble arrangement is optimal. Your answer will be considered correct, if its absolute or relative error does not exceed 10?-?6.
Example Input 50 50 2 Output 0.747474747
题意:有红、蓝俩色弹珠,和一定数量的瓶子,问如何放置使得随机抓取蓝色弹珠的概率最大
解题思路:在损耗蓝色弹珠最少的情况下,使得每个瓶子里抓取蓝色弹珠的概率最大,即在瓶子数少于蓝色弹珠数量的情况下,使其尽可量多的瓶子一定能抓到蓝色瓶子(只放蓝色弹珠)。
注意:这里有个小点要注意,用C++输出double类型的变量时,要使用%f,因为理论上C++的printf函数被没有存%lf。
上代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double n, m, k;
scanf("%lf %lf %lf",&n, &m, &k);
double res;
if(k > m) res = m / k;
else
{
res = (k - 1) / k + (m - k + 1) / (m - k + 1 + n) / k;
}
printf("%.9f",res);
return 0;
}
|