2014北京网络预选赛1005(强连通缩点+期望)HDU5036

Explosion

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 243    Accepted Submission(s): 63

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

题意:RT

思路:如果一个门被打开,那么它里面装的钥匙的门一定都打开了

不难想到,如果存在环,那么选择环里的任何门打开,整个环就都打开了

先强连通缩点,变成了一个DAG

只要一遍DFS处理出哪些点可以被哪些点到达,这个可以用bitset维护

然后要算打开所有门的期望,实际上就是要算出对于每个门来讲,它打开的期望,然后加起来即可

对于门i,如果有x个门可以到达它,那么打开它的概率为cnt[i]/x,期望也即cnt[i]/x,这里的门已经是强连通缩点后的,cnt[i]为i里面门的数量

时间: 2024-10-11 20:49:36

2014北京网络预选赛1005(强连通缩点+期望)HDU5036的相关文章

2014鞍山网络预选赛1005(概率DP)hdu5001

Walk Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 209    Accepted Submission(s): 146 Special Judge Problem Description I used to think I could be anything, but now I know that I couldn't d

2014北京网络预选赛1006(贪心)HDU5037

Frog Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1357    Accepted Submission(s): 364 Problem Description Once upon a time, there is a little frog called Matt. One day, he came to a river.

2014鞍山网络预选赛1010(缩点+高斯消元)hdu5006

Resistance Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 280    Accepted Submission(s): 82 Problem Description Recently DRD got a number of wires. Some of the wires have the resistance 1 ohm

NYOJ-120 校园网络 &amp;&amp;POJ 1236 (强连通缩点targan算法)

链接:click here 题意: 校园网络 时间限制:3000 ms  |  内存限制:65535 KB 难度:5 描述 南阳理工学院共有M个系,分别编号1~M,其中各个系之间达成有一定的协议,如果某系有新软件可用时,该系将允许一些其它的系复制并使用该软件.但该允许关系是单向的,即:A系允许B系使用A的软件时,B未必一定允许A使用B的软件. 现在,请你写一个程序,根据各个系之间达成的协议情况,计算出最少需要添加多少个两系之间的这种允许关系,才能使任何一个系有软件使用的时候,其它所有系也都有软件

[hdu 5032]2014北京网络赛Always Cook Mushroom 离散化+离线线段树/树状数组

Always Cook Mushroom Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 196    Accepted Submission(s): 54 Problem Description Matt has a company, Always Cook Mushroom (ACM), which produces high-q

hdu 5038 (2014北京网络赛G 排序水题)

题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题解:统计数字个数和频率,排序后输出. Sample Input36100 100 100 99 98 1016100 100 100 99 99 1016100 100 98 99 99 97 Sample OutputCase #1:10000Case #2:Bad MushroomCase #3

HDU 5037 FROG 贪心 2014北京网络赛F

题目链接:点击打开链接 题意:有一条小河长为M的小河,可以看作一维轴,小河里存在N个石头,有一个每次能跳L米的小青蛙,随意添加石头保证青蛙能从头跳到尾的,问青蛙使用最优策略跳到对岸最多需要多少次. 思路:不妨假设青蛙每个石头都要经过一次,用step表示青蛙上一次跳的步长,每跳一次对目前点到下一点的距离和step的和与L做比较,如果小与,证明青蛙可以一次跳到这,更新step和青蛙位置,cnt保持不变,若大于,证明青蛙至少需要再跳一次,若lenth<=l,则直接跳,更新step=lenth,cnt+

[2014 北京网络赛]

02 hdu 5033 Building 题目意思: 数轴上有n根柱子,每根柱子有个位置坐标和高度,有q个询问,询问从位置qi能看到的角度(保证左右至少有一个柱子) 解题思路: 单调栈维护一个凸性柱子序列. 离线处理所有的查询,排序,然后扫一遍qi,把柱子插进去,更新单调栈.注意查询位置也要更新栈. 代码: //#include<CSpreadSheet.h> #include<iostream> #include<cmath> #include<cstdio&g

2014牡丹江网络预选赛F题(隐式图BFS暴搜)zoj3814

Sawtooth Puzzle Time Limit: 10 Seconds      Memory Limit: 65536 KB Recently, you found an interesting game called Sawtooth Puzzle. This is a single-player game played on a grid with 3 x 3 cells. Each cell contains a part of an image. Besides, each ed