题目:http://acm.hdu.edu.cn/showproblem.php?pid=5036

Explosion

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 879    Accepted Submission(s): 309

Problem Description
Everyone knows Matt enjoys playing games very much. Now, he is playing such a game. There are N rooms, each with one door. There are some keys(could be none) in each room corresponding to some doors among these N doors. Every key can open only one door. Matt has some bombs, each of which can destroy a door. He will uniformly choose a door that can not be opened with the keys in his hand to destroy when there are no doors that can be opened with keys in his hand. Now, he wants to ask you, what is the expected number of bombs he will use to open or destroy all the doors. Rooms are numbered from 1 to N.
 
Input
The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.

In the first line of each test case, there is an integer N (N<=1000) indicating the number of rooms.

The following N lines corresponde to the rooms from 1 to N. Each line begins with an integer k (0<=k<=N) indicating the number of keys behind the door. Then k integers follow corresponding to the rooms these keys can open.

 
Output
For each test case, output one line "Case #x: y", where x is the case number (starting from 1), y is the answer which should be rounded to 5 decimal places.
 
Sample Input
2
3
1 2
1 3
1 1
3
0
0
0
 
Sample Output
Case #1: 1.00000
Case #2: 3.00000
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5644 5643 5642 5641 5640
 
题意:N扇门,每次可以炸开一道门,并获得这扇门里的钥匙,求炸开门的期望。
题解:
我们要求总期望,可以将每扇门的期望值相加。
然后我们可以把这道题转化为一个有向图,要求解的为有多少个结点可以到结点i(1<=i<=n)。则要炸开第i个门的期望值为 1/能到达i的结点个数 。
最后统计和即可。
统计有多少个结点,可以用bitset优化传递闭包。
 #include<bits/stdc++.h>
using namespace std;
bitset<> a[];
int read()
{
int s=,fh=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')fh=-;ch=getchar();}
while(ch>=''&&ch<=''){s=s*+(ch-'');ch=getchar();}
return s*fh;
}
int main()
{
int T,N,i,j,k,kk,ans,case1=;
double sum;
T=read();
while(T--)
{
N=read();
for(i=;i<=N;i++){a[i].reset();a[i][i]=;}
for(i=;i<=N;i++)
{
k=read();
for(j=;j<=k;j++)
{
kk=read();
a[i][kk]=;
}
}
for(i=;i<=N;i++)
{
for(j=;j<=N;j++)
{
if(a[j][i])a[j]|=a[i];
}
}
sum=0.0;
for(i=;i<=N;i++)
{
ans=;
for(j=;j<=N;j++)
{
if(a[j][i]==)ans++;
}
sum+=(1.0/(double)ans);
}
printf("Case #%d: %.5lf\n",++case1,sum);
}
fclose(stdin);
fclose(stdout);
return ;
}

Hdu 5036-Explosion 传递闭包,bitset,期望/概率的更多相关文章

  1. HDU 5036 Explosion (传递闭包+bitset优化)

    <题目链接> 题目大意: 一个人要打开或者用炸弹砸开所有的门,每个门后面有一些钥匙,一个钥匙对应一个门,告诉每个门里面有哪些门的钥匙.如果要打开所有的门,问需要用的炸弹数量为多少. 解题分 ...

  2. hdu 5036 Explosion(概率期望+bitset)

    Problem Description Everyone knows Matt enjoys playing games very much. Now, he to N. Input The firs ...

  3. hdu 5036 Explosion bitset优化floyd

    http://acm.hdu.edu.cn/showproblem.php?pid=5036 题意就是给定一副有向图,现在需要走遍这n个顶点,一开始出发的顶点是这n个之中的随便一个. 如果走了1,那么 ...

  4. HDU - 5036 Explosion

    Problem Description Everyone knows Matt enjoys playing games very much. Now, he is playing such a ga ...

  5. HDU 3853 期望概率DP

    期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] ,  右移:[x][y ...

  6. 【BZOJ 3652】大新闻 数位dp+期望概率dp

    并不难,只是和期望概率dp结合了一下.稍作推断就可以发现加密与不加密是两个互相独立的问题,这个时候我们分开算就好了.对于加密,我们按位统计和就好了;对于不加密,我们先假设所有数都找到了他能找到的最好的 ...

  7. 【BZOJ 3811】玛里苟斯 大力观察+期望概率dp+线性基

    大力观察:I.从输出精准位数的约束来观察,一定会有猫腻,然后仔细想一想,就会发现输出的时候小数点后面不是.5就是没有 II.从最后答案小于2^63可以看出当k大于等于3的时候就可以直接搜索了 期望概率 ...

  8. 【BZOJ 3925】[Zjoi2015]地震后的幻想乡 期望概率dp+状态压缩+图论知识+组合数学

    神™题........ 这道题的提示......(用本苣蒻并不会的积分积出来的)并没有 没有什么卵用 ,所以你发现没有那个东西并不会 不影响你做题 ,然后你就可以推断出来你要求的是我们最晚挑到第几大的 ...

  9. 【NOIP模拟赛】黑红树 期望概率dp

    这是一道比较水的期望概率dp但是考场想歪了.......我们可以发现奇数一定是不能掉下来的,因为若奇数掉下来那么上一次偶数一定不会好好待着,那么我们考虑,一个点掉下来一定是有h/2-1个红(黑),h/ ...

随机推荐

  1. hibernate - Initial SessionFactory creation failed.org.hibernate.HibernateException

    对于数据库字段映射, 被映射的字段除了提供 getter方法之外, 还需要提供setter方法. 这也是java bean的一些规范. 例如, 题目中的异常 Initial SessionFactor ...

  2. java csv - 读写及其操作.

    今天帮同学处理数据, 主要是从1w多条记录中随机获取8k条, 然后再从8k条记录中随机获取2k条记录. 最后将2k条记录中随机分成10组,使得每组的记录都不重复. 下面将我的代码都贴上来, 好以后处理 ...

  3. 关于Androdi中SQLITE 3采用GBK编码存储,数据库中文乱码问题。

    1.最近开发一个项目,用SQLite Expert Personal打开数据库如下图,title会产生乱码,问题. 2.由于SQL lite默认是存储UTF-8格式,后来更改数据库编码类型为ANSI, ...

  4. wamp不能使用phpmyadmin,提示“You don't have permission to access /phpmyadmin/ on this server.” 转载

    换了win8之后wamp明显不怎么好用了,显示80端口被system占用,后是masql出现了403错误,多番百度谷歌找到了解决方案,这里与大家分享 当你安装完成wamp后,打开localhost或i ...

  5. Go语言探险思考笔记

    最近接触对象存储,国际上鼎鼎有名的Amazon S3还有Google Cloud Service在国内由于防火墙还有机房过远的问题,并不能投入生产使用.国内有名的对象存储,大家众所周知的七牛云,后台就 ...

  6. ERP系统开发平台 (C#语言,支持多数据库)

    C/S系统开发框架-企业版 V4.0 (Enterprise Edition) 简介: http://www.csframework.com/cs-framework-4.0.htm 适用软件:适合开 ...

  7. 工欲善其事必先利其器-Notepad++使用小记(Python)

    大学开始就一直使用Notepad++ 作为代码编辑器,喜欢它的简洁明了,喜欢它的个性,也喜欢它各种各样骚气的插件. 今天闲来无事,写篇文章记录一下平时使用的种种,包括但不限于个性化使用一些宏,快捷键, ...

  8. Python: 使用zipfile+io模块在内存中进行zip操作

    #!/usr/bin/env python #coding=utf-8 ''' 版权所有 (c) 2014 yao_yu (http://blog.csdn.net/yao_yu_126) 本代码采用 ...

  9. Centos + nginx + JBOSS AS 7 搭建Java web application

    最近做了一个Java的web app,一直想在Centos环境中搭建一个完整的web服务器,现在开始动手. 先说说环境: 操作系统: Centos 6.3 WEB服务器: nginx-1.2.5 Ap ...

  10. Laravel框架——任务调度(cron)

    准备: 在服务的/var/spool/cron/root文件中添加代码 cd /var/spool/cron/root 添加以下代码 * * * * * phppath 项目路径/artisan sc ...