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. 每次操作等概率取出一个球(即取出每个球 ...
随机推荐
- classpath和环境变量设置
一.简介: 环境变量是操作系统.应用程序.脚本程序等等的指明灯,能够告诉他们需要的资源在哪里.大多数的 系统都有一些预先设置好的环境变量,当然,我们也可以增加自己的环境变量. 为了看看当前系统的环境变 ...
- 搭建Dynamic Web Project(动态web项目)的springmvc工程1
本文转载自:http://blog.csdn.net/typa01_kk/article/details/45902955 此篇创建Dynamic Web Projec工程(动态web项目),下一篇, ...
- android开源库收集
1. google valley Android网络通信库 git clone https://android.googlesource.com/platform/frameworks/volley ...
- java里的MouseLisetener接口的使用过程==========需要用组件是来注册侦听器
总结:通过匿名类来实现鼠标的监听或者 通过实现接口的方法都可以的 从此是实现MouseListener接口的方式 package com.a.b; import java.awt.Color; im ...
- 命令行调用远程dubbo服务
有时需要对dubbo服务做个简单的测试,或者想看下某个dubbo服务类所提供的方法,可以直接在命令行通过telnet的方式来查看和调用dubbo服务,方法如下: telnet 127.0.0.1 20 ...
- python' s fifth day for me dict
字典 dict : key--vlaue 储存大量的数据,而且是关系型数据,查询速度快(二分查询) 数据类型分类: 可变数据类型(不可哈希):list(列表) , dict(字典), set(集合) ...
- 优化深度神经网络(一) dropout 初始化
Coursera吴恩达<优化深度神经网络>课程笔记(1)-- 深度学习的实用层面 1. Train/Dev/Test sets 训练集(Training sets).验证集(Develo ...
- Android 4学习(8):用户界面 - Fragment
参考<Professional Android 4 Development> Fragment简介 Fragment是我们可以将Activity分成不同的组成部分,这些组成部分拥有自己的生 ...
- linux下的定时或计时操作(gettimeofday等的用法,秒,微妙,纳秒(转载)
一.用select()函数实现非阻塞时的等待时间,用到结构体struct timeval {},这里就不多说了. 二.用gettimeofday()可获得微妙级(0.000001秒)的系统时间,调用两 ...
- CSS中盒子垂直居中的常用方法
在前端开发过程中,盒子居中是常常用到的.其中 ,居中又可以分为水平居中和垂直居中.水平居中是比较容易的,直接设置元素的margin: 0 auto就可以实现.但是垂直居中相对来说是比较复杂一些的.下面 ...