题目链接 : 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. Linux命令整理 - 通用版

    通用版 - 系统架构 /dev 设备文件夹 null 有去无回 mouse /sbin 系统管理必备程序 cfdisk.dhcpcd.dump.e2fsck.fdisk.halt.ifconfig.i ...

  2. HashMap为什么在多线程下会让cpu100%

    首先HashMap并不是sun公司多线程提供的集合,很多时候我们的程序是一个主线程,用了hashmap并没有什么问题,但是在多线程下会出现问题. hashmap是一个哈希表,存储的数据结构也可以是一个 ...

  3. Java 动态代理及AOP实现机制

    AOP实现机制http://www.iteye.com/topic/1116696 AOP: (Aspect Oriented Programming) 面向切面编程AOP包括切面(aspect).通 ...

  4. 旧接口注册LED字符驱动设备(静态映射)

    #include <linux/init.h> // __init __exit #include <linux/module.h> // module_init module ...

  5. TensorFlow 解决“ImportError: Could not find 'cudnn64_6.dll'”

    解决“ImportError: Could not find 'cudnn64_6.dll'” 1. 问题描述 运行一个基于Tensorflow的代码时报错,如下所示: ImportError: Co ...

  6. wepy的第一个demo

    一.在node中安装相应的模块文件,查看文档 二.案例 json部分 { "usingComponents": { "van-button": ".. ...

  7. PayPal支付对接

    开发时间:2019-04-30 我的目标:在我们公司的海外网站上,接入PayPal支付,美国用户在线完成付款. 准备: (1)准备:公司注册信息(执照,注册号,法人等),法人信息(身份证,住址等) ( ...

  8. Git分支操作步骤

    学习操作Git分支,具体如下: - 查看分支 - 创建分支 - 切换分支 - 合并分支 - 解决分支的冲突 方案: Git支持按功能模块,时间,版本等标准创建分支; 分支可以让开发分多条主线同时进行, ...

  9. MemCache--01 解决session

    目录 1. MemCache介绍 2.Session与Cookie介绍 3. 安装部署Nginx 4. 安装部署PHP 5. 安装Mariadb数据库 6. 部署网站(phpMyAdmin) 7. 部 ...

  10. k8s存储

    ·几种存储类型 1)emptyDir emptyDir Volume的生命周期与Pod一致,Pod中的所有容器都可以共享Volume,它们可以指定各自的mount路径,当Pod从节点删除时,Volum ...