luogu嘟嘟嘟




这题刚开始特别容易理解错:直接枚举所有\(n + 1\)种情况,然后算哪一种情况合法,再统计答案。

上述思想的问题就在于我们从已知的结果出发,默认这种每一种情况中取出\(q\)个红球,\(p -q\)个蓝球的概率是1,但实际上无法保证取出的红球或是蓝球的数量刚好是这些。

那应该是啥咧,设袋中红球数量是\(i\),则蓝球就是\(n - i\),那么这种取法的概率是\(\frac{C_{i} ^ {q} * C_{n - i} ^ {p - q}}{C_{n} ^ {p}}\),记为\(p1(i)\)。

在这个条件下,我们再乘以\((i - q) / (n - p)\),才是再取一个球是红球的概率,记为\(p2(i)\)。

如果直接输出\(\sum p2(i)\),那表示的是取出\(p\)个球是任意球的情况下的概率,所以根据条件概率公式,我们应该再除以一个上面的\(\sum p1(i)\)。




还有一个问题,组合数太大,又没有取模。这里有一个trick,就是观察到算出来的概率很小(小于1),因此我们算组合数的时候都取一个log,然后算答案的时候再乘方回来就妥了。




(其实这题可以\(O(1)\)做,答案是\(\frac{q + 1}{p + 2}\),但这个我实在推不出来)

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
#include<assert.h>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e5 + 5;
In ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
In void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
In void MYFILE()
{
#ifndef mrclr
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
} int n, p, q;
int a[maxn], b[maxn]; db f[maxn];
In db logC(int n, int m) {return f[n] - f[m] - f[n - m];} int main()
{
//MYFILE();
int T = 0;
for(int i = 1; i < maxn; ++i) f[i] = f[i - 1] + log(1.0 * i);
while(scanf("%d%d%d", &n, &p, &q) != EOF)
{
db a = 0, b = 0;
for(int i = q; i <= n - p + q; ++i)
{
int j = n - i;
db tp1 = exp(logC(i, q) + logC(n - i, p - q) - logC(n, p));
db tp2 = (i * 1.0 - q) / (n - p);
a += tp1 * tp2, b += tp1;
}
printf("Case %d: %.4lf\n", ++T, a / b);
// printf("%.4lf\n", (q + 1.0) / (p + 2));
}
return 0;
}

HDU4254 A Famous Game的更多相关文章

  1. 各种trick和细节错误汇总

    这篇博客主要是用来记自己写代码的时候犯的各种小技巧和低级失误,好提醒自己,从而尽量缩短debug时间. 点分治 1.求每一个子树到重心的距离的函数接口应该是dfs2(v, eg, e[i].w)而不是 ...

  2. ubuntu kylin 14.04安装Node.js和Famous

    默认使用软件中心安装node.js,然后参考https://famo.us/install进行安装 1.sudo apt-get install git 2.npm install -g yo gru ...

  3. Reading Famous blog to prevent me wasting time on blind wandering

    I can`t help surfing the useless bbs and some other kind of SNS. The time I begin to do it, it costs ...

  4. HDU 4251 The Famous ICPC Team Again 主席树

    The Famous ICPC Team Again Problem Description   When Mr. B, Mr. G and Mr. M were preparing for the ...

  5. ACM The Famous Clock

    The Famous Clock 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 Mr. B, Mr. G and Mr. M are now in Warsaw, ...

  6. hdu 4255 A Famous Grid

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4255 A Famous Grid Description Mr. B has recently dis ...

  7. 07-语言入门-07-A Famous Music Composer

    题目地址: http://blog.csdn.net/sevenmit/article/details/8231994  描述 Mr. B is a famous music composer. On ...

  8. A Famous Music Composer

    描述 Mr. B is a famous music composer. One of his most famous work was his set of preludes. These 24 p ...

  9. HDOJ 4252 A Famous City 单调栈

    单调栈: 维护一个单调栈 A Famous City Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

随机推荐

  1. 史上最全最新Java面试题合集一(附答案)

    下面小编整理了本套java面试题全集,分享给大家,希望对大家的java学习和就业面试有所帮助. 1.面向对象的特征有哪些方面? 答:面向对象的特征主要有以下几个方面: 抽象:抽象是将一类对象的共同特征 ...

  2. Linux Nginx的权限——访问本地目录报错403

    在安装好FastDFS并成功上传图片文件后,根据FastDFS返回的文件地址无法通过HTTP(即浏览器)访问到,报错404或者403. 不管是Error 404还是Error 403,基本都是Ngin ...

  3. java EE学习之数据库操作

    jdbc开发流程 注册驱动 建立连接(Connection) 创建运行SQL的语句(Statement) 运行语句 处理运行结果(ResultSet) 释放资源 注冊驱动有三种方式: Class.fo ...

  4. MVC自定定义扩展点之ActionNameSelectorAttribute+ActionFilterAttribute 在浏览器中打开pdf文档

    仅仅演示 了ASP.MVC 5 下为了在在浏览器中打开pdf文档的实现方式之一,借此理解下自定义ActionNameSelectorAttribute+ActionFilterAttribute 类的 ...

  5. Bigdecimal除法异常

    1.异常信息摘要(详细请见文末): java.lang.ArithmeticException: Non-terminating decimal expansion; no exact represe ...

  6. template中实现加减乘除数学运算

    django模板只提供了加法的filter,没有提供专门的乘法和除法运算:django提供了widthratio的tag用来计算比率,可以变相用于乘法和除法的计算. # 加法{{value|add:1 ...

  7. ORA-00001:unique constraint violated解决

    转自:https://www.2cto.com/database/201211/172340.html ORA-00001:unique constraint violated解决 今天往数据库中插入 ...

  8. 解决Apache启动错误:httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

    启动apache遇到提示: [root@bqh-119 conf]# ../bin/apachectl -thttpd: apr_sockaddr_info_get() failed for bqh- ...

  9. tcping端口检测工具使用

    大家都知道检测网络状态是,无论是服务器/客户机 最常用的就是ping命令,但ping命令只能检测ICMP协议,若对方禁止ping协议了,自然ping命令也就无法检测了,此时,我们可以通过tcping工 ...

  10. thinkphp5自动生成文档/注释代码自动生成api文档

    composer require weiwei/api-doc dev-master 安装之后,readme 有详细的使用说明代码: 部分界面: gitbub:https://github.com/z ...