hdu 5036 Explosion(概率期望+bitset)
- 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 to N.
- 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<=) indicating the number of rooms.
- The following N lines corresponde to the rooms from to N. Each line begins with an integer k (<=k<=N) indicating the number of keys behind the door. Then k integers follow corresponding to the rooms these keys can open.
- For each test case, output one line "Case #x: y", where x is the case number (starting from ), y is the answer which should be rounded to decimal places.
- Case #: 1.00000
- Case #: 3.00000
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<algorithm>
- #include<stdlib.h>
- #include<bitset>
- using namespace std;
- #define N 1006
- int n;
- bitset<N> bs[N];
- int main()
- {
- int t;
- int ac=;
- scanf("%d",&t);
- while(t--){
- scanf("%d",&n);
- for(int i=;i<N;i++){
- bs[i].reset();
- bs[i][i]=true;
- }
- for(int i=;i<n;i++){
- int k;
- scanf("%d",&k);
- for(int j=;j<k;j++){
- int x;
- scanf("%d",&x);
- x--;
- bs[i][x]=true;
- }
- }
- for(int j=;j<n;j++){
- for(int i=;i<n;i++){
- if(bs[i][j]){
- bs[i] |= bs[j];
- }
- }
- }
- double ans=;
- for(int j=;j<n;j++){
- int cnt=;
- for(int i=;i<n;i++){
- if(bs[i][j]){
- cnt++;
- }
- }
- ans+=1.0/cnt;
- }
- printf("Case #%d: %.5lf\n",++ac,ans);
- }
- return ;
- }
hdu 5036 Explosion(概率期望+bitset)的更多相关文章
- hdu 5036 Explosion bitset优化floyd
http://acm.hdu.edu.cn/showproblem.php?pid=5036 题意就是给定一副有向图,现在需要走遍这n个顶点,一开始出发的顶点是这n个之中的随便一个. 如果走了1,那么 ...
- HDU 5036 Explosion (传递闭包+bitset优化)
<题目链接> 题目大意: 一个人要打开或者用炸弹砸开所有的门,每个门后面有一些钥匙,一个钥匙对应一个门,告诉每个门里面有哪些门的钥匙.如果要打开所有的门,问需要用的炸弹数量为多少. 解题分 ...
- HDU - 5036 Explosion
Problem Description Everyone knows Matt enjoys playing games very much. Now, he is playing such a ga ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
- uvalive 7331 Hovering Hornet 半平面交+概率期望
题意:一个骰子在一个人正方形内,蜜蜂在任意一个位置可以出现,问看到点数的期望. 思路:半平面交+概率期望 #include<cstdio> #include<cstring> ...
- OI队内测试一【数论概率期望】
版权声明:未经本人允许,擅自转载,一旦发现将严肃处理,情节严重者,将追究法律责任! 序:代码部分待更[因为在家写博客,代码保存在机房] 测试分数:110 本应分数:160 改完分数:200 T1: 题 ...
- 2016 多校联赛7 Balls and Boxes(概率期望)
Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. ...
- 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】
链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 【bzoj4832】[Lydsy2017年4月月赛]抵制克苏恩 概率期望dp
题目描述 你分别有a.b.c个血量为1.2.3的奴隶主,假设英雄血量无限,问:如果对面下出一个K点攻击力的克苏恩,你的英雄期望会受到到多少伤害. 输入 输入包含多局游戏. 第一行包含一个整数 T (T ...
随机推荐
- 提交App到Apple Store(Xcode4)
昨 天终于顺利把公司的App提交了,还是很开心的.这是我第一个开发超过2个月的项目,开发期间学到了很多东西,接下来的时间我会逐渐梳理一下.来个倒叙, 今天就先说下怎么提交的吧.Xcode4以后,提交过 ...
- android面试题之七
三十六.请解释下在单线程模型中Message.Handler.Message Queue.Looper之间的关系. 简单的说,Handler获取当前线程中的looper对象,looper用来从存放Me ...
- codeforces C. Cd and pwd commands 执行命令行
执行命令来改变路径 cd 并显示路径命令 pwd 一个节目的 抽样: input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd ou ...
- (转)[老老实实学WCF] 第二篇 配置WCF
在上一篇中,我们在一个控制台应用程序中编写了一个简单的WCF服务并承载了它.先回顾一下服务端的代码: using System; using System.Collections.Generic; u ...
- 《第一行代码》学习笔记2-Android开发特色
1.四大组件:活动(Activity),服务(Service),广播接收器(Broadcast Receiver),内容提供器(Content Provider). Activity:应用中看得到的东 ...
- Jquery常用方法(转)
原文:http://www.cnblogs.com/Chenfengtao/archive/2012/01/12/2320490.html jQuery是目前使用最广泛的javascript函数库.据 ...
- TelerikUI_RadGrid_Filter 自定义方法
要设置 EnableLinqExpressions="false",搞了3,4个小时没反应,就是没有设置这个 Protected Sub btnSearch_Click(sende ...
- python字符串的encode和decode
原文 decode的作用是将其他编码的字符串转换成unicode编码. str1.decode('gb2312') #表示将gb2312编码的字符串转换成unicode编码 encode的作用是将un ...
- No enclosing instance of type test8 is accessible. Must qualify the allocation with an enclosing instance of type test8 (e.g. x.new A() where x is an
在编译一个例子时,结果编译时出现: No enclosing instance of type test8 is accessible. Must qualify the allocation wit ...
- 使用UEditor
在http://ueditor.baidu.com/website/上下载官方文件 文本编辑器的配置文件在ueditor.config.js 需要注意一下几点 首先 var URL = window. ...