hdu_4465_Candy
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?
InputThere are several test cases.
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.OutputFor each test case, output one line “Case X: Y” where X is the test case number (starting from 1) and Y is a real number indicating the desired answer.
Any answer with an absolute error less than or equal to 10
-4 would be accepted.Sample Input
- 10 0.400000
- 100 0.500000
- 124 0.432650
- 325 0.325100
- 532 0.487520
- 2276 0.720000
Sample Output
- Case 1: 3.528175
- Case 2: 10.326044
- Case 3: 28.861945
- Case 4: 167.965476
- Case 5: 32.601816
- Case 6: 1390.500000
- 求期望,用log来提高精度并且实现组合数。
- #include<iostream>
- #include<cstdlib>
- #include<stdio.h>
- #include<math.h>
- #define ll __int64
- using namespace std;
- #define N 1000005
- double a[N<<1];
- int main()
- {
- a[0]=0;
- for(int i=1;i<N*2;i++)
- a[i]=a[i-1]+log(1.0*i);
- int n;
- double p;
- int t=0;
- while(~scanf("%d%lf",&n,&p))
- {
- double ans=0,res1,res2;
- for(int i=0;i<=n;i++)
- {
- res1=(a[2*n-i]-a[n]-a[n-i])+(n+1)*log(p)+(n-i)*log(1-p);
- res2=(a[2*n-i]-a[n]-a[n-i])+log(1-p)*(n+1)+log(p)*(n-i);
- ans+=exp(res1)*i+exp(res2)*i;
- }
- printf("Case %d: %.6f\n",++t,ans);
- }
- }
hdu_4465_Candy的更多相关文章
随机推荐
- easyui 删除行的时候 引起的 bug
问题场景 easyui 编辑里 有删除行的功能 文档提供的方法如下 $aplgrid为grid 的容器 ind 为当前行的索引 $aplgrid.datagrid('deleteRow', ind); ...
- XPath路径表达式笔记(转载)
简单说,xpath就是选择XML文件中节点的方法. 所谓节点(node),就是XML文件的最小构成单位,一共分成7种. - element(元素节点)- attribute(属性节点)- text ( ...
- 如何优雅地使用Markdown (Sublime 3 + MarkdownEditing+OmniMarkupPreviewer)
最近开始上手Sublime 3 作为Markdown 的重度使用者自然关于Markdown的插件是必不可少的 . 在这里记录分享一下我常用的两款Markdown插件. MarkdownEditing ...
- Glide实现查看图片和保存图片到手机
两种方式, 推荐方式一 方式一 downloadOnly 创建一个 ImageActivity public class ImageActivity extends AppCompatActivity ...
- Element和vue框架报错提示
上面报错提示Error in render function: "TypeError:Cannot read property '$options' of undefined" 就 ...
- Installing TensorFlow on Ubuntu
1.安装方法有4种,官方推荐是第一种. virtualenv(官方推荐) "native" pip Docker Anaconda 2.基于virtualenv的 ...
- HTML 折行br
HTML 折行 如果您希望在不产生一个新段落的情况下进行换行(新行),请使用 <br /> 标签: <p>This is<br />a para<br /&g ...
- SVNKit学习——使用低级别的API(ISVNEditor接口)直接操作Repository的目录和文件(五)
本文是参考官方文档的实现,官方wiki:https://wiki.svnkit.com/Committing_To_A_Repository 本文核心使用的是ISVNEditor这个接口直接对Re ...
- 定制UITabBar显示样式
定制UITabBar显示样式 思路是这样子的: 1. 初始化UITabBarController,并装载进来几个其他的ViewController 2. 获取每个控制器的UITabBarItem 3. ...
- Hyperledger Fabric 1.0 学习搭建 (二)--- 源码及镜像文件处理
2.1下载Fabric源码下载Fabric源码是因为要用到源码中提到的列子和工具, 工具编译需要用到go语言环境, 因此需要把源码目录放到$GOPATH下. 通过1.3中go的安装配置, $GOPAT ...