hdu_4336_Card Collector
As a smart boy, you notice that to win the award, you must buy much more snacks than it seems to be. To convince your friends not to waste money any more, you should find the expected number of snacks one should buy to collect a full suit of cards.
InputThe first line of each test case contains one integer N (1 <= N <= 20), indicating the number of different cards you need the collect. The second line contains N numbers p1, p2, ..., pN, (p1 + p2 + ... + pN <= 1), indicating the possibility of each card to appear in a bag of snacks.
Note there is at most one card in a bag of snacks. And it is possible that there is nothing in the bag.OutputOutput one number for each test case, indicating the expected number of bags to buy to collect all the N different cards.
You will get accepted if the difference between your answer and the standard answer is no more that 10^-4.Sample Input
1
0.1
2
0.1 0.4
Sample Output
10.000
10.500 这道题一开始怎么都没想懂,其实就是一个容斥,分别计算收集齐1-n套卡的概率。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
#define maxn 70
#define N 25
double e[N];
double p[N];
int n; int main()
{
LL a,b,i; //scanf("%ld",&T);
while(~scanf("%d",&n))
{
double ans=0;
double res=1.0;
int flag=0;
double tmp;
memset(p,0,sizeof(p));
for(int i=0;i<n;i++)
{
scanf("%lf",&p[i]);
res-=p[i];
}
for(int i=1;i<(1<<n);i++)
{
tmp=0,flag=0;
for(int j=0;j<n;j++)
if(i&((1<<j)))
flag++,tmp+=p[j];
if(flag&1)
ans+=1.0/tmp;
else
ans-=1.0/tmp;
}
printf("%.5lf\n",ans);
}
return 0;
}
hdu_4336_Card Collector的更多相关文章
- The The Garbage-First (G1) collector since Oracle JDK 7 update 4 and later releases
Refer to http://www.oracle.com/technetwork/tutorials/tutorials-1876574.html for detail. 一些内容复制到这儿 Th ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- Jmeter plugin jp@gc - PerfMon Metrics Collector
Jmeter由于是开源工具,所以目前有很多插件可以供使用,最简单的方法是先把Plugin Manager安装了 下载地址:https://jmeter-plugins.org/wiki/Plugins ...
- Spring AOP 开发中遇到问题:Caused by: java.lang.IllegalArgumentException: warning no match for this type name: com.xxx.collector.service.impl.XxxServiceImpl [Xlint:invalidAbsoluteTypeName]
在网上找了很多,都不是我想要的,后来发现是我在springaop注解的时候 写错了类名导致的这个问题 @Pointcut("execution(* com.xxx.collector.ser ...
- HDU2639Bone Collector II[01背包第k优值]
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDOJ 4336 Card Collector
容斥原理+状压 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 2602 Bone Collector WA谁来帮忙找找错
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- Bone Collector(01背包)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...
- (三)CMS Collector
有些资料中,为区别parallel collector ,将应用与gc并发成为并行,在接下来的文章中,仍称为并发. -XX:useConcMarkSweepGC,可以用于minor gc和major ...
随机推荐
- JavaScript的进阶之路(二)函数简介,变量、作用域和内存问题
<h3>ECMAScript中函数不存在函数签名的概念,没有重载</h3><h3>无需指定返回值,可以在任何时候返回任何值.未指定返回值的函数,返回的是一个特殊的u ...
- C# 使用Guid类生成不重复的随机数
什么是Guid GUID(全局唯一标识符) 全局唯一标识符(GUID,Globally Unique Identifier)是一种由算法生成的二进制长度为128位的数字标识符.GUID ...
- SQLServer 2008 新增T-SQL 简写语法
1.定义变量时可以直接赋值 DECLARE @Id int = 5 2.Insert 语句可以一次插入多行数据 INSERT INTO StateList VALUES(@Id, 'WA'), (@I ...
- Studying TCP's Congestion Window using NS
Studying TCP's Congestion Window using NS How to obtain TCP's CWND value The most important value th ...
- 如何让LoadRunner实现多个场景运行?
如何让LoadRunner实现多个场景运行? 发布时间: 2013-11-29 10:59 作者: stevenlee 来源: 51Testing软件测试网博客 字体: 小 中 大 ...
- linux命令整理
Linux系统命令 1. ls 查看某个 目录下 所有文件的大小总和 ls -lR| awk 'BEGIN{size=0;} /^[-l]/{size+=$5;print $0;} END{print ...
- 解决yii2.0里url重写引用js路径问题(@web/的用法)
在实际项目中,为了seo优化,使用了伪静态,开启了url重写
- Spark Broadcast内幕解密:Broadcast运行机制彻底解密、Broadcast源码解析、Broadcast最佳实践
本课主题 Broadcast 运行原理图 Broadcast 源码解析 Broadcast 运行原理图 Broadcast 就是将数据从一个节点发送到其他的节点上; 例如 Driver 上有一张表,而 ...
- CentOS 系统新装每次必看,直到背下。。
1.CentOS7 mini 修改网卡信息: vi /etc/sysconfig/network-scripts/ifcfg-ens192 ONBOOT = yes vi /etc/resolv.co ...
- g++: error: unrecognized command line option ‘-std=C++11’
一个小程序,在编译的时候出错,原来使用的编译命令是 g++ -std=C++11 array.cpp -o array.exe g++: error: unrecognized command lin ...