problem Description
is inch inch inch is from 1 to N.
Input
Case is an integer N (n<=-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
Case " Case #x: y " where is Case from 1 is 5 decimal places.
Sample Input
2 3 1 2 1 3 1 1 3 0 0 0
Sample Output
Case #11.00000 case #23.00000
Source
ACM/ICPC Asia regional Beijing Online
Test Instructions:
a person to open or use a bomb smashed all the doors, each door there are some keys, a key to a door, a door with a key to open the corresponding door, tell each door what the key of the door, and asked how many bombs to use.
Ideas:
considering the probability that each point needs to be opened with a bomb, the sum of the probabilities of all points is the solution. The probability that each point v needs to be opened with a bomb is 1/s, S is the number of U (u->v unicom), and then it becomes the transitive closure of this diagram, optimized with Bitset. Why is 1/s, because this S door inside must use a bomb to break open, and hit v probability is 1/s.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <stdlib.h>7#include <bitset>8 using namespacestd;9 #defineN 1006Ten intN; OneBitset<n>Bs[n]; A intMain () - { - intT; the intAc=0; -scanf"%d",&t); - while(t--){ -scanf"%d",&n); + for(intI=0; i<n;i++){ - Bs[i].reset (); +bs[i][i]=true; A } at for(intI=0; i<n;i++){ - intK; -scanf"%d",&k); - for(intj=0; j<k;j++){ - intx; -scanf"%d",&x); inx--; -bs[i][x]=true; to } + } - for(intj=0; j<n;j++){ the for(intI=0; i<n;i++){ * if(Bs[i][j]) { $Bs[i] |=Bs[j];Panax Notoginseng } - } the } + Doubleans=0; A for(intj=0; j<n;j++){ the intCnt=0; + for(intI=0; i<n;i++){ - if(Bs[i][j]) { $cnt++; $ } - } -ans+=1.0/CNT; the } -printf"Case #%d:%.5lf\n",++Ac,ans);Wuyi } the return 0; -}
View Code
Recommend
HDU 5036 Explosion (probability expectation +bitset)