2012Chengdu B (快速组合数)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-10-17)
Description
He has been eating one candy a day for several days. But one day, when opening a box, he finds no candy left. Before opening the other box, he wants to know the expected number of candies left in the other box. Can you help him?
Input
For each test case, there is a single line containing an integer n (1 ≤ n ≤ 2 × 10 5) and a real number p (0 ≤ p ≤ 1, with 6 digits after the decimal).
Input is terminated by EOF.
Output
Any answer with an absolute error less than or equal to 10 -4 would be accepted.
Sample Input
100 0.500000
124 0.432650
325 0.325100
532 0.487520
2276 0.720000
Sample Output
Case 2: 10.326044
Case 3: 28.861945
Case 4: 167.965476
Case 5: 32.601816
Case 6: 1390.500000
公式快速排列组合函数:logC(m,n),zuhe[i]其实就是i的阶乘,然后给取log值
这样zuhe[m]-zuhe[n]-zuhe[m-n]就是C(m,n)的log值
然后把其余也取对数,然后再求exp就好了!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define M(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f using namespace std; int n;
double p;
double zuhe[]; double logC(int m,int n)
{
return zuhe[m]-zuhe[n]-zuhe[m-n];
} int main()
{
int cas = ;
zuhe[] = ;
for(int i = ;i<;i++) zuhe[i] = zuhe[i-]+log(i*1.0);
while(scanf("%d%lf",&n,&p)==)
{
double res = ;
for(int i = ;i<=n;i++)
{
res+=(n-i)*exp(logC(n+i,i)+(n+)*log(p)+(i)*log(-p));
res+=(n-i)*exp(logC(n+i,i)+(n+)*log(-p)+(i)*log(p));
}
printf("Case %d: %.16f\n",cas++,res);
}
return ;
}
2012Chengdu B (快速组合数)的更多相关文章
- NOIP2011多项式系数[快速幂|组合数|逆元]
题目描述 给定一个多项式(by+ax)^k,请求出多项式展开后x^n*y^m 项的系数. 输入输出格式 输入格式: 输入文件名为factor.in. 共一行,包含5 个整数,分别为 a ,b ,k , ...
- 【板子】gcd、exgcd、乘法逆元、快速幂、快速乘、筛素数、快速求逆元、组合数
1.gcd int gcd(int a,int b){ return b?gcd(b,a%b):a; } 2.扩展gcd )extend great common divisor ll exgcd(l ...
- UVALive 7040 Color (容斥原理+逆元+组合数+费马小定理+快速幂)
题目:传送门. 题意:t组数据,每组给定n,m,k.有n个格子,m种颜色,要求把每个格子涂上颜色且正好适用k种颜色且相邻的格子颜色不同,求一共有多少种方案,结果对1e9+7取余. 题解: 首先可以将m ...
- Paths on a Grid POJ - 1942 组合数学 (组合数的快速计算)
题意:格路问题 没什么难度 难点在于如何快速计算相对较大的组合数 思路:运用手写计算组合数的方式进行计算 如c(8,3) 如果手算就是 8*7*6/(3*2*1)这样可以很快得解出 计算代码为: ...
- Gym - 101775A Chat Group 组合数+逆元+快速幂
It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: ...
- HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description Sample Input 2 Sample Outp ...
- 【BZOJ4870】组合数问题(动态规划,矩阵快速幂)
[BZOJ4870]组合数问题(动态规划,矩阵快速幂) 题面 BZOJ 洛谷 题解 显然直接算是没法做的.但是要求的东西的和就是从\(nk\)个物品中选出模\(k\)意义下恰好\(r\)个物品的方案数 ...
- [BZOJ3209]花神的数论题 组合数+快速幂
3209: 花神的数论题 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2498 Solved: 1129[Submit][Status][Disc ...
- 牛客网 牛客小白月赛1 I.あなたの蛙が帰っています-卡特兰数,组合数阶乘逆元快速幂
I.あなたの蛙が帰っています 链接:https://www.nowcoder.com/acm/contest/85/I来源:牛客网 这个题有点意思,是卡特兰数,自行百度就可以.卡特兰数用处 ...
随机推荐
- Java反射API使用实例
/** * 访问Class对应的类所包含的注释:getAnnotation();getDelaredAnnotation(); * 访问Class对应的类所包含的内部类:getDecl ...
- libuv(不断更新)
/* * Initialize the uv_async_t handle. A NULL callback is allowed. * * Note that uv_async_init(), un ...
- 20145212 《Java程序设计》第5周学习总结
20145212 <Java程序设计>第5周学习总结 教材学习内容总结 第八章 1.Java中所有错误都会被打包为对象,通过try和catch语法可以对代表错误的对象做处理. try{ . ...
- C++11
http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list http://www.open-std.o ...
- Favorite Games
Samurai II: Vengeance: http://www.madfingergames.com/games
- js随机生成N位数
function RondomPass(number){ var arr = new Array; "); ;i<number;i++){ ); arr[i] =arr1[n] ; / ...
- ecshop新增一个编辑器
在ecshop的后台新增一个编辑器框 步骤一:找到lib_main.php 文件:admin/includes/lib_main.php. 找到变量:function create_html_edit ...
- GPRS/3G
像GPRS/3G模块之类的应用,需要连接,登陆,初始化等步骤完成后才能传输数据,而这些步骤又比较耗时. 所以用 状态机 + 超时 的机制来实现比较合理. 如下代码片段来描述数据透传 : 状态机 + 超 ...
- servlet中的相对路径和绝对路径 及/, ./, ../的区别
./ 当前目录../ 父级目录/ 根目录资源寻找都是依靠路径,资源存储方式是按照哈希表运算的,所以路径的计算其实就是哈希值的计算. servlet中,所有路径的配置都要用绝对路径. 什么是绝对路径,就 ...
- jQuery/js 正则收集(邮件验证、)
var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; //验证邮箱的正则表达式if( ...
快速排列组合函数:logC(m,n),zuhe[i]其实就是i的阶乘,然后给取log值