题目: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. 线性布局LinearLayout和相对布局RelativeLayout 之间的比较

    LinearLayout和RelativeLayout之间: 共有属性:java代码中通过btn1关联次控件android:id="@+id/btn1" 控件宽度android:l ...

  2. 初学HTML5系列二:HTML5新增的事件属性

    Window事件属性: 属性 值 描述 onafterprint  script 文档打印之后运行的脚本. 属性发生于用户设置页面打印并且打印对话框已出现之后. onbeforeprint  scri ...

  3. windows服务启动 1053错误

    1.问题描述 今天在启动一个Windows服务时,服务启动不了,且提示:1053错误 那么是什么导致了1053错误呢? 2.他山之石 百度了一下,发现有人作出下面的解释并给出了解决方法: “常常是因为 ...

  4. andriod 中设置sdk升级代理服务器

    Android SDK 在线更新镜像服务器资源: 大连东软信息学院镜像服务器地址: http://mirrors.neusoft.edu.cn 端口:80 北京化工大学镜像服务器地址: IPv4: h ...

  5. (一)问候Struts2

    第一节:Struts2 简介 主页:http://struts.apache.org/在用户请求和模块化处理方面以及页面的展现这块,Struts2 发挥的屌炸天作用:相对于传统的Jsp+Servlet ...

  6. MySQL常见问题汇总(原创)

    本文记录了使用Mysql时遇到的问题,持续更新中... 1.在windows命令行下登录mysql时报错: C:\Program Files\MySQL\MySQL Server 5.0\bin> ...

  7. java-成员变量的属性与成员函数的覆盖

    java中在多态的实现是通过类的继承或者接口的实现来完成的. 在类继承或者接口实现过程中就会涉及到成员属性以及成员函数的重写,需要注意的是,成员函数的重写是直接覆盖父类的(继承中),但是成员变量重写是 ...

  8. 【工具篇】source Insight

    不多说,阅读代码利器. 一.修改背景颜色 使用淡绿色更护眼(听说而已),菜单“选项”>>“属性”,使用自己喜欢的颜色吧.我的淡绿色RGB是181,236,207 二.行号,空格替换tabs ...

  9. _BLOCK_TYPE_IS_VALID 问题解析及处理

    直接原因: 释放内存时,内存已经被修改或释放. 产生可能: 1.内存越界操作,踩了待释放指针头信息. 2.重复释放指针. 处理: 采用排除法,逐步屏蔽掉一些代码,当屏蔽某些代码时,不抛此异常,说明问题 ...

  10. 百度劫持js代码

    js代码为: var myDate=new Date(); //返回一日期对象,可以调用getDate(),内容为当前时间,这句是新建一个对象d建好对象后d就有函数date()中的所有特性 var h ...