M - Marbles Lucky Distribution(贪心)

M - Marbles Lucky Distributionhttps://vjudge.csgrandeur.cn/problem/Gym-101845M

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

Copy

50 50 2

output

Copy

0.747474747
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double n,m,k;
    cin>>n>>m>>k;
    if(k==1)
        printf("%.7lf\n",(double)m/(n+m));
    else
    {
        if(m>=k)
            printf("%.7lf\n",(double)(m-k+1)/(double)(n+m-k+1)+(double)(k-1)*(1/k));
        else
            printf("%.7lf\n",(double)(m/k));
    }
    return 0;
}

 题解:

类似于贪心。三种情况:1.只有一个瓶子,概率就为蓝球/(蓝球+红球)。2.蓝球的数量大于等于瓶子k,最优解为k-1个瓶子,每个瓶子放一个蓝球,最后一个瓶子,将剩下的蓝球和红球放进去,概率如上。3.蓝球的数量小于等于瓶子k,最优解为每个瓶子放一个蓝球,直到蓝球用完了,剩下的随便放,概率如上

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值