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 ...
随机推荐
- lianxi
package dududu; public class qiqiqi { public static void main(String[] args) { // TODO 自动生成的方法存根 ; ; ...
- 【Python】raw转义字符
r"hi" 这里字符串前面加了r,是raw的意思,它表示对字符串不进行转义.为什么要加这个?你可以试试print "\bhi"和r"\bhi" ...
- Sass初入门
什么是CSS预处理器? CSS预处理器定义了一种新的语言,其基本思想是,用一种专门的编程语言,为CSS增加了一些编程的特性,将CSS作为目标生成文件,然后开发者就只要使用这种语言进行编码工作. 什 ...
- 任务九:使用HTML/CSS实现一个复杂页面
任务目的 通过实现一个较为复杂的页面,加深对于HTML,CSS的实战能力 实践代码的复用.优化 任务描述 通过HTML及CSS实现设计稿 设计稿PSD文件(点击下载),效果如 效果图(点击打开) 整个 ...
- BEM,SASS,LESS,bootstrap:如何有效地将这些方法,工具和框架聪明地整合?
https://medium.com/@andersonorui_/bem-sass-and-bootstrap-9f89dc07d20f Bootstrap是一个“HTML,CSS和Javascri ...
- ASP.NET 4.5 MVC 4 无法在Windows2008的IIS7.0上解决方案
环境 : Windows2008 R2 Standard IIS 7.5 VS2012 SQL2005 最近才接触MVC4 自己做了个小实例 准备部署在 win2008 的IIS7.5 ...
- mongoDb 命令
1.显示MongoDB的服务器统计:db.stats() 2.创建数据库:use dbname 3.删除数据库:db.dropDatabase() 4.检查当前选择的数据库:db 5.检查数据库列表: ...
- ELK_Elastic Search和kibana版本对应关系
https://www.elastic.co/downloads/past-releases/kibana-5-0-0 https://www.elastic.co/downloads/past-re ...
- pyqt5加载网页的简单使用
如下初步使用了pyqt5,构造了一个webview来加载网址,呈现网页. 1.安装pyqt5包,可使用douban的源 pip install pyqt5 -i http://pypi.douban. ...
- WebExtensions小例
一:简述 扩展是修改Web浏览器功能的代码位.它们使用标准的Web技术(JavaScript,HTML和CSS)以及一些专用的JavaScript API编写.其中,扩展程序可以向浏览器添加新功能或更 ...