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 ...
随机推荐
- npm 和 bower的区别
npm和bower在功能上有一定的重合,但不是互斥关系,可以在项目中同时运用.区别在于npm在设计之初就采用了的是嵌套的依赖关系树.一个普通的前端包的依赖树比较长,npm 会将开发环境一起下载下来, ...
- swift 自定义导航栏颜色
func setNavigationApperance(){ //自定义导航栏颜色 [self.navigationController?.navigationBar.barTintColor = U ...
- Django之验证码 + session 认证
验证码 + session认证 目录结构 . └── project ├── app01 │ ├── admin.py │ ├── apps.py │ ├── __init__.py │ ...
- HLS直播和时移项目上线
兄弟姐妹们: 天翼视讯的高清HLS直播和时移项目上线,测试观看地址为:http://118.85.192.228/live/,同时支持移动终端和pc终端.移动终端支持ios client和androi ...
- Struts2 页面url请求怎样找action
1.我们使用最原始的方法去查找action.不同注解. struts.xml文件先配置 <!-- 新闻信息action --> <action name="newsInfo ...
- c#利用VM_COPYDATA实现进程间通信
c#进程间的通信方式很多种,只会这种,感觉比较简单.不懂原理,能用就行. 假设有两个程序:server(主进程),client(子进程) 1.server端: /*定义一个结构体,用来接收从子进程传过 ...
- Javascript进阶篇——(DOM—认识DOM、ByName、ByTagName)—笔记整理
认识DOM文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法.DOM 将HTML文档呈现为带有元素.属性和文本的树结构(节点树). 将HTML代码分解 ...
- javascript 获取滚动条高度+常用js页面宽度与高度(转)
/******************** *获取窗口滚动条高度 ******************/ function getScrollTop() { var scrollTop=0; if(d ...
- asp net 编程问题 实现下一篇 和上一篇效果
首先是access数据库,有一个名为news的表,里面有三个字段,分别为id,classid 和name 其中id为主键,classid可以重复 现在有以下数据: id classid name 1 ...
- Windows命令行(DOS命令)教程 -1 (转载) http://www.pconline.com.cn/pcedu/rookie/basic/10111/15325.html
一.命令行简介 命令行就是在Windows操作系统中打开DOS窗口,以字符串的形式执行Windows管理程序. 在这里,先解释什么是DOS? DOS--Disk Operation System 磁盘 ...