LightOJ 1342 Aladdin and the Magical Sticks 期望(结论题)
题意:n根木棍,每根木棍都有一个权值,木棍有可识别的木棍和不可识别的木棍,每次抽取木棍时,会累加权值,如果是可识别的木棍就不放回,不可识别的木棍就放回,问每根木棍至少被抽取一次,权值的期望是多少。
思路:论文题?
1类棍子只会拿起一次,ans+=权值
2类棍子会拿起多次,ans+=权值*h[n] h[n]为调和级数第n项
证明的博客
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,b,a) for(int i=b;i>=a;i--)
#define clr(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pii pair<int,int >
using namespace std;
typedef long long ll;
ll rd() {
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'') {
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='') {
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
const int maxn=+;
double f[maxn];
int main(){
int T,cat=;
for(int i=;i<=;i++){
f[i]=f[i-]+1.0/i;
}
cin>>T;
while(T--){
int n;
double ans=;
cin>>n;
rep(i,,n){
int w,ty;
cin>>w>>ty;
if(ty==){
ans+=w;
}else{
ans+=w*f[n];
}
}
printf("Case %d: %.7f\n",cat++,ans);
}
}
LightOJ 1342 Aladdin and the Magical Sticks 期望(结论题)的更多相关文章
- LightOJ 1342 Aladdin and the Magical Sticks [想法题]
题目链接 : http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27050 --------------------------- ...
- LightOj_1342 Aladdin and the Magical Sticks
题目链接 题意: 地上有n种棍子, 其中有两种类型, 一种类型是可识别, 一种类型是不可识别, 每个棍子都有一个权值. 当你捡到可识别的, 那么你以后就不会再捡这个棍子, 如果是不可识别的, 那么你有 ...
- 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 1038 - Race to 1 Again(期望+DP)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1038 题意是:给你一个N (1 ≤ N ≤ 105) 每次N都随机选一个因子d,然后让 ...
- LightOj 1030 - Discovering Gold(dp+数学期望)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...
- LightOJ 1321 - Sending Packets 简单最短路+期望
http://www.lightoj.com/volume_showproblem.php?problem=1321 题意:每条边都有概率无法经过,但可以重新尝试,现给出成功率,传输次数和传输时间,求 ...
- 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 ...
随机推荐
- 拾遗:btrfs
#扫描 btrfs 文件系统btrfs device scan btrfs device scan /dev/sda #创建子卷或快照 btrfs subvolume create /mnt/btrf ...
- 剑指offer——570~n-1中缺失的数字
题目:0~n-1中缺失的数字. 一个长度为n-1的递增排序数组中的所有数字都是唯一的,并且每个数字都在范围0~n-1之内. 在范围0~n-1内的n个数字中有且只有一个数字不在该数组中,请找出这个数字. ...
- kafka单机版的安装、集群部署 及使用
1.安装kafka(单机版) 1.1上传 kafka_2.11-2.0.0.tgz 到 /root/Downloads 1.2解压 tar 包 tar -zxvf kafka_2.11-2.0.0.t ...
- Linux的各个发行版本(二)
CentOS CentOS是世界上使用的最好的Linux服务器发行版之一,占了全世界Linux服务器的30%. 它是Red Hat 的衍生产品,提供了稳定的服务器环境. 特点: 支持的X86-64架构 ...
- position:relative/static/fixed/absolute定位的区别以及使用场景
absolute是相对于自己最近的父元素来定位的,relative是相对于自己来定位的 relative 不脱离文档流,absolute 脱离文档流.也就是说:relative 的元素尽管表面上看到它 ...
- 检测apache状态,当apache处于非running状态如何脚本启动
编写脚本内容 #!/bin/bashURL="http://127.0.0.1/"curlit(){curl --connect-timeout 15 --max-time 20 ...
- GIT 部分记录
关于版本回退 git reset HEAD^ #回退a.py这个文件的版本到上一个版本 git reset HEAD^ a.py git reset HEAD a.py 我试了一下以上2种方式 ...
- Saks就const解释
In my last column, I discussed one of the reasons why the rules by which a compiler can place data i ...
- map 结构体
map<node,int> 需要运算符重载< 请注意,不同的node,请务必让它们可以区分出来(node a,b a<b or b<a) 如 node { int a,i ...
- Vue Router基础
路由 安装 vue-router 起步 <router-link to="/foo">Go to Foo</router-link> <router- ...