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 ...
随机推荐
- 1-4 Sass的基本特性-基础
[Sass]声明变量 定义变量的语法: 在有些编程语言中(如,JavaScript)声明变量都是使用关键词“var”开头,但是在 Sass 不使用这个关键词,而是使用大家都喜欢的美元符号“$”开头.我 ...
- xunsearch bsd 10.1安装心酸路。。。
cc -c -I/usr/local/xunsearch/include/ test.cpp cc test.o -L/usr/local/xunsearch/lib -lscws -lm -o te ...
- Android Studio最新稳定版下载 - 百度网盘(更新于2017年7月14日)
Android Studio是一个为Android平台开发程序的集成开发环境,其包含用于构建Android应用所需的所有工具.Android Studio 2.3.3为最新稳定版(截止到2017年7月 ...
- python三次输入错误验证登录
# login.py# 提示用户输入用户名和密码# 验证用户名和密码# 如果v错误,则输出用户名或密码错误# 如果成功,则输出欢迎,xxxnum = 0while True: name = input ...
- SQL Server ->> 尝试优化ETL中优化Merge性能
这几天突发想到在ETL中Merge性能的问题.思路的出发点是Merge到目标表需要扫描的数据太多,而现实情况下,假设应该是只有一小部分会被更新,而且这部分数据也应该是比较新的数据,比方说对于想Fact ...
- js 日期格式化及日期增减
//Demo:new Date().format("yyyy-MM-dd hh:mm:ss.SSS") Date.prototype.format = function (form ...
- 绘制播放音乐时的音波图形的View
绘制播放音乐时的音波图形的View 这个效果类似于这个哦: 效果如下: 源码: MusicView.h 与 MusicView.m // // MusicView.h // Music // // C ...
- IE 浏览器中英文切换
Oracle相关产品浏览器中可以调节显示中英文
- 对EJB的认识
对EJB的认识 接触EJB以来有一段时间了,走马观花一样把它所涉及到的东西看了一遍,随着深入了解越来越感觉到ejb的很强大,用了java后觉的java好用.学历SSH觉的比java好用.学了ejb觉的 ...
- Django 查询集的过滤内置条件
条件选取querySet的时候,filter表示=,exclude表示!=.querySet.distinct() 去重复__exact 精确等于 like 'aaa' __iexact 精确等于 忽 ...