题目链接 : 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. hacker101教学笔记--introduction--the web in depth

    hacker101笔记 提前准备:运行java的环境 burp proxy(代理) firefox(浏览器) xss 可以控制参数,发送JavaScript到服务器,再从服务器反映到浏览器上面< ...

  2. 四种pop模式介绍

    四种pop模式介绍 URL:http://www.hishop.com.cn/ecschool/jd/show_21195.html URL:https://zhidao.baidu.com/ques ...

  3. Java io基础

    1.什么是IO? Java IO即Java 输入输出系统.不管我们编写何种应用,都难免和各种输入输出相关的媒介打交道,其实和媒介进行IO的过程是十分复杂的,这要考虑的因素特别多,比如我们要考虑和哪种媒 ...

  4. JS屏蔽鼠标右键

    //方法1: function stop() {    return false;}document.oncontextmenu = stop;//方法2: window.document.oncon ...

  5. Java核心技术

    [Java核心技术36讲]1.谈谈你对Java平台的理解 2.Exception和Error有什么区别 3.谈谈final.finally.finalize有什么不同?4.强引用.软引用.弱引用.虚引 ...

  6. JAVA总结--泛型

    泛型 :程序设计语言的一种特性:将类型参数化: 特征:凡是涉及到强制类型转化的地方,使用泛型均会编译出现问题:泛型仅仅在编译时进行校验,使用泛型的对象,其本质的类型依然不变: ps:不存在泛型数组 一 ...

  7. [2019杭电多校第二场][hdu6602]Longest Subarray(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6602 题目大意为求最长的区间,满足C种数字在区间内要么不出现,要么出现的次数都不小于K. 大致的分析一 ...

  8. HDU 5945 题解(DP)(单调队列)

    题面: Fxx and game Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) T ...

  9. 【CF321E】+【bzoj5311】

    决策单调性 + WQS二分 贴个代码先... //by Judge #pragma GCC optimize("Ofast") #include<bits/stdc++.h& ...

  10. MVC一个action对应多个视图的写法

    一,如下代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...