upc 3025 Fleecing the Raf?e

Posted kissheart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了upc 3025 Fleecing the Raf?e相关的知识,希望对你有一定的参考价值。

Fleecing the Raf?e

时间限制: 2 Sec  内存限制: 64 MB  Special Judge
提交: 179  解决: 49
[提交] [状态] [讨论版] [命题人:外部导入]

题目描述

A tremendously exciting raf?e is being held,with some tremendously exciting prizes being given out. All you have to do to have a chance of being a winner is to put a piece of paper with your name on it in the raf?e box. The lucky winners of the p prizes are decided by drawing p names from the box. When a piece of paper with a name has been drawn it is not put back into the box – each person can win at most one prize.
Naturally, it is against the raf?e rules to put your name in the box more than once. However, it is only cheating if you are actually caught, and since not even the raf?e organizers want to spend time checking all the names in the box, the only way you can get caught is if your name ends up being drawn for more than one of the prizes. This means that cheating and placing your name more than once can sometimes increase your chances of winning a prize.
You know the number of names in the raf?e box placed by other people, and the number of prizes that will be given out. By carefully choosing how many times to add your own name to the box, how large can you make your chances of winning a prize (i.e., the probability that your name is drawn exactly once)?

 

输入

The input consists of a single line containing two integers n and p (2 ≤ p ≤ n ≤ 106 ), where n is the number of names in the raf?e box excluding yours, and p is the number of prizes that will be given away.

 

输出

Output a single line containing the maximum possible probability of winning a prize, accurate up to an absolute error of 10-6 .

 

样例输入

3 2

 

样例输出

0.6

 

提示

样例输入2
23 5
样例输出2
0.45049857550

题意

除了你的其他N个人各写一张带名字纸条放进抽奖箱里,共有P个奖,你可以写任意X张纸条放进抽奖箱里,你不能获奖两次,求X的最优解使得获奖概率最大。

分析

概率问题,数学推公式,但是求组合数过程会爆精度,所以要把式子化简一下。

技术分享图片

 

技术分享图片
///  author:Kissheart  ///
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e6+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c==-) f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-0;return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
int main()
{
    int n,p;
    int x;
    scanf("%d%d",&n,&p);
    if(n==1)
    {
        printf("0.5
");
        return 0;
    }
    x=n/(p-1);

    double ans=1.0*x*p/(x+n-p+1);
    for(int i=0;i<=p-2;i++)
    {
        ans=ans*(n-i);
        ans=ans/(x+n-i);
    }

    printf("%.11lf
",ans);
    return 0;
}
View Code

 

以上是关于upc 3025 Fleecing the Raf?e的主要内容,如果未能解决你的问题,请参考以下文章

Fleecing the Raffle(NCPC 2016 暴力求解)

[UPC | 山东省赛] The Largest SCC | Tarjan强连通分量瞎搞 + 状态还原

ecnu 3025

前端学习(3025):vue+element今日头条管理-侧边导航菜单

前端学习(3025):vue+element今日头条管理-关于默认子路由的问题

数学习题:求解不定方程a^2 + b^2 = 3025