spoj1026 favorite dice
#include <bits/stdc++.h>
using namespace std;
int n,t;
const int N = ;
double dp[N];
/*
甩一个n面的骰子,问每一面都被甩到的需要甩的次数期望是多少。
dp[i]:已经甩到i个面了,要达到n个面还需要次数的期望
显然dp[n] = 0
那么逆序分析:dp[i] :再甩一次,有(n-i)/n的概率甩到其他的
有i/n的概率甩到已经被甩过的。
那么 dp[i]=(n-i)/n*dp[i+1]+i/n*dp[i]+1(+1是因为再甩了一次)
化简可得到 dp[i]=dp[i+1]+n/(n-i)
*/
int main()
{
scanf("%d",&t);
while(t--){
scanf("%d",&n);
dp[n] =;
for(int i =n-;i>=;i--){
dp[i] = dp[i+]+(n/(n-(double)i));
}
printf("%.2f\n",dp[]);
}
return ;
}
spoj1026 favorite dice的更多相关文章
- 题解:SPOJ1026 Favorite Dice
原题链接 题目大意 给你一个n个面的骰子,每个面朝上的几率相等,问每个面都被甩到的期望次数 题解 典型的赠券收集问题. 我们考虑当你手上已有\(i\)种不同的数,从集合中任选一个数得到新数的概率,为\ ...
- HDOJ 4652 Dice
期望DP +数学推导 Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 三种renderman规范引擎的dice对比
次表面做的有些烦躁,既然如此,索性先记一下前一阵比较的PIXIE.3delight.prman的dice方式. 研究过reyes的人都知道dice,简而言之,就是为了生成高质量高精度的图片(电影CG) ...
- LightOJ 1248 Dice (III) 概率
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- hdu 4586 Play the Dice 概率推导题
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- 概率 Gym 100502D Dice Game
题目传送门 /* 题意:两个人各掷两个骰子,给出每个骰子的最小值和最大值,其余值连续分布 问两人投掷,胜利的概率谁大 数据小,用4个for 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...
- HDU 5955 Guessing the Dice Roll
HDU 5955 Guessing the Dice Roll 2016 ACM/ICPC 亚洲区沈阳站 题意 有\(N\le 10\)个人,每个猜一个长度为\(L \le 10\)的由\(1-6\) ...
- UVALive 7275 Dice Cup (水题)
Dice Cup 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/D Description In many table-top ...
- HDU 4586 A - Play the Dice 找规律
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
随机推荐
- Python——追加学习笔记(三)
错误与异常 AttributeError:尝试访问未知的对象属性 eg. >>> class myClass(object): ... pass ... >>> m ...
- June 06th 2017 Week 23rd Tuesday
At the touch of love, everyone becomes a poet. 一谈到爱,每个人都变成了一位诗人. Sweet words always have the power o ...
- June 02nd 2017 Week 22nd Friday
A burden of one's choice is not felt. 爱挑的担子不嫌重. When doing things I love to do, I seldom feel tired ...
- 团队第三次scrum
长大一条龙之课表查询 一.设计概要 本次内容主要是实现了长大一条龙系统的课表查询功能,我们的这个项目严格遵守MVC架构,采用前后端分离的策略.我们将课表查询分为二层,DAO层:负责与数据进行交互,读写 ...
- SAP成都研究院廖婧:SAP C4C社交媒体集成概述
曾经有朋友在知乎上向我提问,咨询在SAP成都研究院工作的体验. 当时,我的回答提到一点,SAP注重工作与生活的平衡,这也是SAP中国官网强调的一点. https://www.sap.com/china ...
- react中使用css动画效果
index.js import React, { Component, Fragment } from 'react'; class App extends Component { construct ...
- idea 使用maven构建项目时,target bytecode version经常自动变化
解决方法:在工程的pom.xml中添加 <build> <plugins> <plugin> <groupId>org.apache.maven.plu ...
- build.gradle中的dependencies
demo_myna中的build.gradle中的dependencies是依赖项目.比如之前开发的一个项目A,现在新的项目B要使用项目A的功能,那么把项目A作为类库关联进来,这样b就能直接使用A的功 ...
- js 跳转整理
js方式的页面跳转1.window.location.href方式 <script language="javascript" type="text/java ...
- Python—面向对象05 反射
反射,通过字符串映射到对象属性 class People: country='China' def __init__(self,name,age): self.name=name self.age ...