题目传送门

  题意: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 期望(结论题)的更多相关文章

  1. LightOJ 1342 Aladdin and the Magical Sticks [想法题]

    题目链接 : http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27050 --------------------------- ...

  2. LightOj_1342 Aladdin and the Magical Sticks

    题目链接 题意: 地上有n种棍子, 其中有两种类型, 一种类型是可识别, 一种类型是不可识别, 每个棍子都有一个权值. 当你捡到可识别的, 那么你以后就不会再捡这个棍子, 如果是不可识别的, 那么你有 ...

  3. LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...

  4. LightOJ 1348 Aladdin and the Return Journey

    Aladdin and the Return Journey Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged ...

  5. LightOJ 1038 - Race to 1 Again(期望+DP)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1038 题意是:给你一个N (1 ≤ N ≤ 105) 每次N都随机选一个因子d,然后让 ...

  6. LightOj 1030 - Discovering Gold(dp+数学期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...

  7. LightOJ 1321 - Sending Packets 简单最短路+期望

    http://www.lightoj.com/volume_showproblem.php?problem=1321 题意:每条边都有概率无法经过,但可以重新尝试,现给出成功率,传输次数和传输时间,求 ...

  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. shell 删除超过30天的文件和目录

    #!/bin/bash location="/root/sqlbak/" find $location -mtime +30 -type d |xargs rm -rf #删除目录 ...

  2. 拾遗:systemctl --user

    参考:https://wiki.gentoo.org/wiki/Systemd systemd 支持普通用户定义的 unit[s] 开机启动 systemctl --user enable/disab ...

  3. docker学习日记一(镜像构建-container commit和image build)

    构建镜像的方式两种: 一.根据已有的container构建-docker container commit 二.根据已有的image构建-docker image build(推荐) containe ...

  4. [已解决]报错:ValueError: Expected 2D array, got scalar array instead

    报错代码: new_x = 84610 pre_y = model.predict(new_x) print(pre_y) 报错结果: ValueError: Expected 2D array, g ...

  5. springboot配置swagger-rest文档

    前言 swagger是一个很好的restful形式的api文档,可以通过比较小的侵入来提供很好的restful的文档.因为swagger是依赖服务生成的,所以其实是依赖服务的,这也算是它的一个小缺点吧 ...

  6. Mysql优化-典型的服务器配置

    内存配置相关参数 mysql内存分配需要考虑到操作系统需要使用的内存,其他应用程序所要使用的内存,mysql的会话数以及每个会话使用的内存,然后就是操作系统实例所使用的内存.生产环境的mysql往往都 ...

  7. kubeadm部署一个Kubernetes集群

    kubeadm是官方社区推出的一个用于快速部署kubernetes集群的工具.这个工具能通过两条指令完成一个kubernetes集群的部署: # 创建一个 Master 节点 $ kubeadm in ...

  8. leetcood学习笔记-69-x的平方根

    题目描述: 第一次提交:(会超时) class Solution: def mySqrt(self, x: int) -> int: if x==0 or x==1: return x for ...

  9. Java-Class-@I:org.springframework.beans.factory.annotation.Autowired

    ylbtech-Java-Class-@I:org.springframework.beans.factory.annotation.Autowired 1.返回顶部   2.返回顶部 1. pack ...

  10. scrapy-redis分布式爬取tencent社招信息

    scrapy-redis分布式爬取tencent社招信息 什么是scrapy-redis 目标任务 安装爬虫 创建爬虫 编写 items.py 编写 spiders/tencent.py 编写 pip ...