题目链接 : http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27050

------------------------------------------------------------------------------------------------------------

我们先考虑这个问题

有一堆牌 其中$n$张牌抽到后不放回 另$m$张牌抽到后放回

求每张牌都抽到过至少一次 需要的抽牌次数的期望

对于这个问题 我们显然可以列出期望的等式后转化为$dp$方程求解 复杂度$O(nm)$

------------------------------------------------------------------------------------------------------------

然而这个复杂度并不够优

这时 我们需要考虑到如果全部都是放回的话 复杂度只有$O(n + m)$ $($同样可以用$dp$求解$)$

如果我们把不放回的都看做放回的 那么一旦抽到不放回的 $($ 第一次抽到除外 $)$ 就不算这次的

于是不放回的只用在最后减去贡献即可

------------------------------------------------------------------------------------------------------------

由于不放回的牌的期望均为$1$ 放回的牌的期望也均为一个定值

因此再加上权值也是很容易的

//由于通过$dp$计算出来的值刚好是欧拉常数$γ$的前$n$项和

//所以就直接预处理出来对于每个$n$的$γ$即可

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = ;
double r[N];
int t, n;
double ans;
int main()
{
for(int i = ; i <= ; ++i)
r[i] = r[i - ] + 1.0 / i;
scanf("%d", &t);
for(int ca = ; ca <= t; ++ca)
{
int x, y;
scanf("%d", &n);
ans = ;
for(int i = ; i <= n; ++i)
{
scanf("%d%d", &x, &y);
if(y == )
ans += x;
else
ans += r[n] * x;
}
printf("Case %d: %.7f\n", ca, ans);
}
return ;
}

LightOJ 1342 Aladdin and the Magical Sticks [想法题]的更多相关文章

  1. LightOJ 1342 Aladdin and the Magical Sticks 期望(结论题)

    题目传送门 题意:n根木棍,每根木棍都有一个权值,木棍有可识别的木棍和不可识别的木棍,每次抽取木棍时,会累加权值,如果是可识别的木棍就不放回,不可识别的木棍就放回,问每根木棍至少被抽取一次,权值的期望 ...

  2. LightOj_1342 Aladdin and the Magical Sticks

    题目链接 题意: 地上有n种棍子, 其中有两种类型, 一种类型是可识别, 一种类型是不可识别, 每个棍子都有一个权值. 当你捡到可识别的, 那么你以后就不会再捡这个棍子, 如果是不可识别的, 那么你有 ...

  3. HDU 4972 Bisharp and Charizard 想法题

    Bisharp and Charizard Time Limit: 1 Sec  Memory Limit: 256 MB Description Dragon is watching NBA. He ...

  4. CodeForces 111B - Petya and Divisors 统计..想法题

    找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...

  5. HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...

  6. LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...

  7. LightOJ 1348 Aladdin and the Return Journey

    Aladdin and the Return Journey Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged ...

  8. Lightoj 1348 Aladdin and the Return Journey (树链剖分)(线段树单点修改区间求和)

    Finally the Great Magical Lamp was in Aladdin's hand. Now he wanted to return home. But he didn't wa ...

  9. LightOJ 1344 Aladdin and the Game of Bracelets

    It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...

随机推荐

  1. [19/05/13-星期一] HTML_head标签 和 body标签_文本标签

    一.概念 概念:超文本标记语言 作用:需要将Java在后台根据用户的请求处理结果在浏览器显示给用户.数据已经过来了,但是显示可能比较凌乱,所以html应用而生,就像写作文要加标点看着舒服. 在浏览器中 ...

  2. BUUCTF--findit

    测试文件:https://buuoj.cn/files/7b8602971727c6c82ec0d360d5cad2c0/6a428ff2-25d7-403c-b28e-3f980a10a5a2.ap ...

  3. 获取请求头中User-Agent工具类

    public class AgentUserKit { private static String pattern = "^Mozilla/\\d\\.\\d\\s+\\(+.+?\\)&q ...

  4. Python subprocess ffmpeg

    # -*- coding:utf-8 -*- import os, sys, getopt import numpy as np import subprocess as sp import cv2 ...

  5. Linux--shell grep与正则表达式--04

    一.grep程序 Linux下有文本处理三剑客:grep.sed.awk grep:文本 行过滤工具 sed:文本 行编辑器(流编辑器) awk:报告生成器(做文本输出格式化) 1.grep grep ...

  6. PAT考砸有感

    今天下午1点半到4点半是考PAT的时间,考场很安静,大家都在安静地思考,唯一能够听到的是键盘敲击的声音,和几只ACM大牛提前离场的自信的声音,那仿佛就是在说着:哈哈哈,又一次轻松过.考试结束,我还在调 ...

  7. 1145. Hashing - Average Search Time (25)

    The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...

  8. openGL如何在改变窗口大小时,使自己的图形不被拉伸

    这里要注意两个概念:视口和视景体,当视口的纵横比和视景体的纵横比相同的时候,改变窗口大小,图像才不会变形: 视景体是指成像景物所在空间的集合.它是一个空间集合体. 单个的视景体,比如一个球体,若要完全 ...

  9. qt05 音乐播放器

    这些步骤可实现音乐播放,但是列表不能显示 music = new QMediaPlayer(this); playlist = new QMediaPlaylist(this); playlist-& ...

  10. .iml文件恢复

    基于maven的java工程 执行 mvn idea:module可恢复.iml文件