LightOJ 1342 Aladdin and the Magical Sticks [想法题]
题目链接 : 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 [想法题]的更多相关文章
- LightOJ 1342 Aladdin and the Magical Sticks 期望(结论题)
题目传送门 题意:n根木棍,每根木棍都有一个权值,木棍有可识别的木棍和不可识别的木棍,每次抽取木棍时,会累加权值,如果是可识别的木棍就不放回,不可识别的木棍就放回,问每根木棍至少被抽取一次,权值的期望 ...
- LightOj_1342 Aladdin and the Magical Sticks
题目链接 题意: 地上有n种棍子, 其中有两种类型, 一种类型是可识别, 一种类型是不可识别, 每个棍子都有一个权值. 当你捡到可识别的, 那么你以后就不会再捡这个棍子, 如果是不可识别的, 那么你有 ...
- HDU 4972 Bisharp and Charizard 想法题
Bisharp and Charizard Time Limit: 1 Sec Memory Limit: 256 MB Description Dragon is watching NBA. He ...
- CodeForces 111B - Petya and Divisors 统计..想法题
找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...
- HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- LightOJ 1348 Aladdin and the Return Journey
Aladdin and the Return Journey Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged ...
- 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 ...
- 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 ...
随机推荐
- 006/搭建fabric(二)
准备vmware虚拟机,并安装完ubuntu系统后.继续搭建fabric运行环境... 0.打开终端,切换root身份.目的:后续操作即可不用sudo... 右键->open Terminal- ...
- display:table
display:table的CSS声明能够让一个HTML元素和它的子节点像table元素一样.使用基于表格的CSS布局,使我们能够轻松定义一个单元格的边界.背景等样式,而不会产生因为使用了table那 ...
- e.target与e.currentTarget的区别,事件冒泡与事件捕获 ,事件委托
e.target与e.currentTarget的区别:https://www.jianshu.com/p/1dd668ccc97a 事件冒泡与事件捕获 :https://www.jianshu.co ...
- Python自学第二天学习之《元组与字典》
一. 元组:tuple类型,元组一级元素 不能修改 不能增加 不能删除,是有序的. 格式 :tu=(1,2,3,4,5,6) 1.类型转换: #字符串转换成元组 b=“123” c=tuple(b) ...
- eclipse 使用技巧、经验 (编码、格式化模板、字体)
版权声明:本文为博主原创文章,未经博主同意不得转载.安金龙 的博客. https://blog.csdn.net/smile0198/article/details/28697515 1.设置编码为U ...
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency
在整合ssm框架,测试service层的时候报错 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: ...
- Nginx优化总结
目录 Nginx性能优化概述 一. 压力测试工具实战 二.了解影响性能指标 三.系统性能优化 四.静态资源优化 Nginx性能优化概述 基于Nginx性能优化,那么在性能优化这一章,我们将分为如下几个 ...
- substring c# js java
c# String.SubString(int index,int length) String.SubString(int start) 等效于 javascript stringObject.su ...
- Intellij IDEA 插件开发秘籍
来这里找志同道合的小伙伴! 这里总结一下 Intellij IDEA 插件开发的知识,供大家参考,本篇文章包含以下内容: 开发环境搭建 Component 介绍 Extension Point And ...
- pip安装包出现timeout的解决办法
今天安装django时老是出现timeout WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, sta ...