NEUOJ 1484概率dp
来源:互联网 发布:淘宝发错货怎么理赔 编辑:程序博客网 时间:2024/06/06 07:51
1484: Hengheng eat noodles
时间限制: 1 Sec 内存限制: 256 MB提交: 20 解决: 17
[提交][状态][讨论版]
题目描述
As we all know,Hengheng(big cow),very look forward to meizi and he often declare that he want to find a meizi.As Hengheng’s admirer, Jiajia decides to help Hengheng to achieve his dream in Christmas Day. In this day, Jiajia asks Hengheng to eat noodles with a pretty meizi(don’t ask why Jiajia didn’t chase this pretty meizi). When eating noodles, Hengheng is so excited that he wants the qq of the meizi. However, a unlucky thing happen.The pretty meizi says she won’t give Hengheng her qq unless Hengheng can solve her question. Hengheng promise without hesition.The pretty meizi picks up a noodle and say with sexy voice, “We all know a noodle has two ends,and now I has n noodles, so there are 2*n ends at all. Out of interest,I will link these ends randomly,and then I wonder the mathematical expectation of the circle I could get.” Although Hengheng is big cow, he can’t wait to get the qq so he can’t think as long as he see the pretty. So he ask Jiajia to solve the problem for him. Luckily,after 1000 ms,Jiajia give the right answer. And Hengheng got the qq successfully. Now, if you are Jiajia, could solve the problem within 1000 ms and help Hengheng get the qq.
输入
The first line is a integer t,indicate the number of cases.(t<=10)
For each case follow,there is a integer n,imply the amount of noodles.(n<=10^6)
输出
For each case, print a double E,represent the mathematical expectation.(E retain 6 decimal)
样例输入
3124
样例输出
1.0000001.3333331.676190
提示
来源
新星赛2014
All Copyright Reserved 2010-2015 NEU-ACM TEAM
GPL2.0 2003-2013 HUSTOJ Project TEAM
概率dp啊,令d[i]表示前i根面条能形成的期望,那么有两种可能,第i根和自己连接起来期望为d[i-1]+1,第i根不和自己连接起来,期望为d[i].
第i根和自己连接起来的概率为1/(2*i-1).全概率公式就行
#include <stdio.h>#include <stdlib.h>const int maxn = 1e6 + 5;double d[maxn];void init(int n){ d[0] = 0; for(int i = 1; i <= n; i++) { double p = 1.0/(2*i-1); d[i] = p*(1+d[i-1]) + d[i-1]*(1-p); }}int main(int argc, char const *argv[]){ int t; scanf("%d",&t); init(1000000); while(t--) { int n; scanf("%d",&n); printf("%.6f\n", d[n]); } return 0;}
1484: Hengheng eat noodles
时间限制: 1 Sec 内存限制: 256 MB提交: 20 解决: 17
[提交][状态][讨论版]
题目描述
As we all know,Hengheng(big cow),very look forward to meizi and he often declare that he want to find a meizi.As Hengheng’s admirer, Jiajia decides to help Hengheng to achieve his dream in Christmas Day. In this day, Jiajia asks Hengheng to eat noodles with a pretty meizi(don’t ask why Jiajia didn’t chase this pretty meizi). When eating noodles, Hengheng is so excited that he wants the qq of the meizi. However, a unlucky thing happen.The pretty meizi says she won’t give Hengheng her qq unless Hengheng can solve her question. Hengheng promise without hesition.The pretty meizi picks up a noodle and say with sexy voice, “We all know a noodle has two ends,and now I has n noodles, so there are 2*n ends at all. Out of interest,I will link these ends randomly,and then I wonder the mathematical expectation of the circle I could get.” Although Hengheng is big cow, he can’t wait to get the qq so he can’t think as long as he see the pretty. So he ask Jiajia to solve the problem for him. Luckily,after 1000 ms,Jiajia give the right answer. And Hengheng got the qq successfully. Now, if you are Jiajia, could solve the problem within 1000 ms and help Hengheng get the qq.
输入
The first line is a integer t,indicate the number of cases.(t<=10)
For each case follow,there is a integer n,imply the amount of noodles.(n<=10^6)
输出
For each case, print a double E,represent the mathematical expectation.(E retain 6 decimal)
样例输入
3124
样例输出
1.0000001.3333331.676190
提示
来源
新星赛2014
All Copyright Reserved 2010-2015 NEU-ACM TEAM
GPL2.0 2003-2013 HUSTOJ Project TEAM
- NEUOJ 1484概率dp
- NEUOJ 1302: 最大子序列(双向dp)
- 概率dp
- ##概率dp##
- 概率dp
- 概率dp
- 概率dp
- 概率dp
- 概率dp
- 概率dp
- 概率dp
- 概率dp
- 概率DP
- 概率DP
- 概率dp
- 概率dp
- dp-概率dp
- 【区间dp,概率dp】
- USACO:2.1.5 Hamming Codes 汉明码
- datastage报Windows Scripting Engine错误的解决办法
- 智能指针陷阱
- 细说 HttpHandler 的映射过程
- 单片机编程中软件定时器
- NEUOJ 1484概率dp
- SQL索引一步到位
- CentOS安装
- 第一章第十一题
- B. Fox And Two Dots
- JavaScript编程规范-有利于效率和可读性
- 自学历程
- Android编译服务器的管理之二:管理用户
- 第一章第十二题