题目链接 : 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. 绕过安全狗Apache4.0版本

    参数拦截:script.空格and空格.空格or空格.union select.user() 绕过: and.order by绕过:  内联注释 union select绕过: union%23%0a ...

  2. sql中unique和distinct

    在SQL语法里面,有unique和distinct两个关键字, unique是distinct的同义词,功能完全相同.distinct是标准语法,其他数据库 sql server,db2,oracle ...

  3. mysql续集(查询部分)

    mysql查询部分,从基础的查询到关键字,where子句,group by, order by, limit ,having,子查询分为from子查询和where子查询,左连接和右连接,内连接的连表查 ...

  4. SQL SERVER SP命令及实现跨数据库查询

    1.数据库: (1)sp_helpdb:报告有关指定数据库或所有数据库的信息. 例:sp_helpdb   --显示所有数据库信息(名称.大小等) 例:sp_helpdb Recruitment   ...

  5. JavaScript基础5——动态显示时间

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. 基本SQL查询语句

    使用Emp表和Dept表完成下列练习 Emp员工表 empno ename job Mgr Hiredate Sal Comm Deptno 员工号 员工姓名 工作 上级编号 受雇日期 薪金 佣金 部 ...

  7. Route的exact属性

    exact是Route下的一个属性,react路由会匹配到所有能匹配到的路由组件,exact能够使得路由的匹配更严格一些. exact的值为bool型,为true时表示严格匹配,为false时为正常匹 ...

  8. dict/json转xml

    在json转xml时,首先传进来的一定是一个dict,如果不是需要转一下,然后开始迭代,遇到dict则递归,如果是list则循环递归,否则认为是文字,将其写入,逻辑不复杂,因为为了代码循环不是太频繁, ...

  9. mycat权威指南阅读笔记--序言1

    前言 mycat官方地址http://www.mycat.io/,mycat是关系数据库的中间件,也就是说它可以把后端的多个数据库,抽象成一个关系数据库. mycat能干啥 官方文档介绍,主要是用来做 ...

  10. oracle 汇编04

    General-Purpose Instructions The general-purpose instructions perform basic data movement, memory ad ...