LightOJ 1248 Dice (III) (水题,期望DP)
题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少。
析:这个题很水啊,就是他解释样例解释的太。。。我鄙视他,,,,,
dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新的一面,另一种是看到旧的一面,然后就很出答案了。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} double dp[maxn]; int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%d", &n);
dp[1] = 1.0;
for(int i = 2; i <= n; ++i)
dp[i] = (dp[i-1] * (n - i + 1) + i - 1) / (n - i + 1) + 1.0;
printf("Case %d: %.10f\n", kase, dp[n]);
}
return 0;
}
LightOJ 1248 Dice (III) (水题,期望DP)的更多相关文章
- LightOj 1248 - Dice (III)(几何分布+期望)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1248 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望 ...
- 【非原创】LightOj 1248 - Dice (III)【几何分布+期望】
学习博客:戳这里 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望: 第一个面第一次出现的概率是p1 n/n; 第二个面第一次出现的概率是p2 (n-1)/n; 第三个 ...
- LightOJ 1248 Dice (III) (期望DP / 几何分布)
题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...
- LightOJ - 1248 Dice (III) —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1248 1248 - Dice (III) PDF (English) Statistics Forum Tim ...
- LightOJ 1248 Dice (III) 概率
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- LightOJ 1248 Dice (III)
期望,$dp$. 设$dp[i]$表示当前已经出现过$i$个数字的期望次数.在这种状态下,如果再投一次,会出现两种可能,即出现了$i+1$个数字以及还是$i$个数字. 因此 $dp[i]=dp[i]* ...
- 1248 - Dice (III)
1248 - Dice (III) PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given ...
- [LOJ 1248] Dice (III)
G - Dice (III) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descri ...
- 【BZOJ2510】弱题 期望DP+循环矩阵乘法
[BZOJ2510]弱题 Description 有M个球,一开始每个球均有一个初始标号,标号范围为1-N且为整数,标号为i的球有ai个,并保证Σai = M. 每次操作等概率取出一个球(即取出每个球 ...
随机推荐
- ORA-28595: Extproc 代理: DLL 路径无效解决办法
报错信息: ORA-28595: Extproc 代理: DLL 路径无效 ORA-06512: 在 "SDE.ST_GEOMETRY_SHAPELIB_PKG", line 70 ...
- PHP数组排序和按数量分割
用PHP自带array_multisort函数排序 <?php $data = array(); $data[] = array('volume' => 67, 'editi ...
- MVC匿名类传值学习
刚接触MVC+EF框架不久,但一直很困惑的就是控制器能否及如何向视图传递匿名类数据.宝宝表示很讨厌去新建实体类啦,查询稍有不同就去建一个实体类不是很麻烦吗,故趁阳光正好,周末睡到自然醒后起来尝试了之前 ...
- ActiviMQ(1)
1. ActiviMQ是实现JMS接口和规范的消息中间件(Provider), 2. JMS,Java Message Service, java消息服务,是JavaEE中的一个技术 3. JMS规范 ...
- 简述FPGA的一些优势
优势一: 更大的并行度.这个主要是通过并发和流水两种技术实现. A:并发是指重复分配计算资源,使得多个模块之间可以同时独立进行计算.这一点与现在的多核和SIMD技术相似.但相对与SIMD技术,FPGA ...
- 「自己开发直播」rtmp-nginx-module实现直播状态、观看人数控制
这是自己搭建直播服务器.开发直播平台系列的文章,前面两篇文章分别为: 通过Nginx-rtmp-module搭建直播服务器并实现直播 实现nginx-rtmp-module多频道输入输出与权限控制 这 ...
- 【转】使用Jmeter针对ActiveMQ JMS Point To Point压力测试
准备工作 针对JMS类型的Sampler,需要额外的jar包(这里用的是apache ActiveMQ,将下载的AMQ apache-activemq-5.5.0根目录下的activemq-all-5 ...
- fatal: read error: Connection reset by peer解决办法
标签(空格分隔): ceph源码安装,git 问题描述: 源码安装ceph,克隆代码时提示如下错误: [root@localhost ~]# git clone git://github.com/ce ...
- python开发模块基础:collections模块¶miko模块
一,collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdic ...
- Cassandra学习六 一些知识点
http://www.flyml.net/2016/09/08/cassandra-tutorial-java-api-example/ Cassandra对查询的支持很弱,只支持主键列及索引列的查询 ...