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来源:牛客网 这个题有点意思,是卡特兰数,自行百度就可以.卡特兰数用处 ...
随机推荐
- CSS基础知识真难啊-background-渐变
文章参考 http://www.zhangxinxu.com/wordpress/?p=727 http://www.uqu8.com/html/2014/html-css_1105/176.html ...
- Myeclipse的show in breadcrumb
m如何取消eclipse的show in breadcrumb 不小心点了show in breadcrumb,在编辑器界面上面多一层路径条,多余碍事,不晓得怎么取消,搞了半天终于弄好,方法如下: 点 ...
- Python基本数据类型之list
一.创建列表: li = [] li = list() name_list = ['alex', 'seven', 'eric'] name_list = list(['alex', 'seven', ...
- bootstrap学习总结-04 常用标签2
1 表格 Bootstrap为表格设计了漂亮的样式. 1)表格基本实例 任意 <table> 标签添加 .table. <table class="table"& ...
- what's the CRSF ??
What's CSRF attack ? CSRF(" Cross-site request forgery!" 跨站请求伪造) 用实例讲原理: 我们假设一个银行网站A,一个 ...
- vim配置有竖对齐线
https://github.com/lvxiaobo616/vim-indent-guides 参考 https://github.com/Yggdroot/indentLine 先安装 Yggdr ...
- ecshop 远程图片本地化
define('IN_ECS', true); require(dirname(__FILE__) . '/includes/init.php'); $smarty->assign('siteD ...
- 在浏览器输入 URL 后会发生什么?超级详细介绍
一个古老的面试问题:当你在浏览器中输入whosmall.com并且按下回车之后发生了什么? 不过我们不再局限于平常的回答,而是想办法回答地尽可能具体,不遗漏任何细节. 这将是一个协作的过程,所以深入挖 ...
- 爬虫3 html解析器 html_parser.py
#coding:utf8 import urlparse from bs4 import BeautifulSoup import re __author__ = 'wang' class HtmlP ...
- 视频直播APP开发分析
视频直播APP开发到目前为止都还是热门的一个行业,而且发展到现在直播的种类非常多,很多行业都打入了直播行业,再也不是单纯的人物直播这么单一了.视频直播APP开发行业就像是吃螃蟹,来的早的人不懂如何吃, ...
快速排列组合函数:logC(m,n),zuhe[i]其实就是i的阶乘,然后给取log值