hdu5306 Explosion
题意
有n个房间,每个房间里面有若干把钥匙,每把钥匙可以打开对应的一扇门。如果手中没有钥匙,就要随机轰炸一个房间来打开这个房间。如果有钥匙,就要去打开这些房间。问期望轰炸次数是多少。
思路
根据期望的线性性质,总期望轰炸次数就是每个房间被轰炸的概率\(\times\) 1。
所以就考虑每个房间被轰炸的概率。
先理解一下题意,也就是说只要打开了一扇门就可以打开若干扇门。所以可以从每个房间向他房间中钥匙所对应的房间连边。
每个房间被轰炸当且仅当所有可以到达他的房间都没有被轰炸。
所以把上面所说的边放过了。跑一边传递闭包。第i个点被轰炸的概率就是\(1/anc(i)\),\(anc(x)\)表示在传递闭包中x所能到达的点的个数。
求传递闭包可以用\(floyd\),再加上\(bitset\)的优化
所以最终答案就是$$\sum_{i=1}^n\frac{1}{anc_i}$$
代码
/*
* @Author: wxyww
* @Date: 2019-01-23 15:39:31
* @Last Modified time: 2019-01-23 16:03:40
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<bitset>
using namespace std;
typedef long long ll;
const int N = 1010;
bitset<N>f[N];
ll read() {
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
void solve(int x) {
int n = read();
for(int i = 1;i <= n;++i) {
int k = read();
f[i].set(i);
for(int j = 1;j <= k;++j) {
int x = read();
f[x].set(i);
}
}
for(int k = 1;k <= n;++k)
for(int i = 1;i <= n;++i)
if(f[i][k]) f[i] |= f[k];
double ans = 0;
for(int i = 1;i <= n;++i) {
ans += (double)1 / f[i].count();
f[i].reset();
}
printf("Case #%d: %.5lf\n",x,ans);
}
int main() {
int T = read();
for(int i = 1;i <= T;++i) {
// MEM();
solve(i);
}
return 0;
}
hdu5306 Explosion的更多相关文章
- NBUT 1635 Explosion(最小顶点覆盖)
[1635] Explosion 时间限制: 10000 ms 内存限制: 65535 K 问题描述 there is a country which contains n cities connec ...
- Codeforces Gym 191033 E. Explosion Exploit (记忆化搜索+状压)
E. Explosion Exploit time limit per test 2.0 s memory limit per test 256 MB input standard input out ...
- hdu5306 Gorgeous Sequence
hdu5306 Gorgeous Sequence 题目大意 给你一个序列,维护区间和,区间chkmin和区间最大值 数据范围 数据组数T,序列长度n,操作次数m $T = 100,\sum n ...
- 【hdu5306】 Gorgeous Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5306 (题目链接) 题意 区间取$min$操作,区间求和操作,区间求最值操作. Solution 乱搞一通竟然A ...
- Explosion at Cafebazaar
Explosion at Cafebazaar 时间限制: 1 Sec 内存限制: 128 MB 题目描述 You are an engineer at Cafebazaar and your sp ...
- 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp
2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp [P ...
- hdu 5036 Explosion(概率期望+bitset)
Problem Description Everyone knows Matt enjoys playing games very much. Now, he to N. Input The firs ...
- HDU - 5036 Explosion
Problem Description Everyone knows Matt enjoys playing games very much. Now, he is playing such a ga ...
- HDU 5036 Explosion (传递闭包+bitset优化)
<题目链接> 题目大意: 一个人要打开或者用炸弹砸开所有的门,每个门后面有一些钥匙,一个钥匙对应一个门,告诉每个门里面有哪些门的钥匙.如果要打开所有的门,问需要用的炸弹数量为多少. 解题分 ...
随机推荐
- Junit概述
Junit -> java unit.也就是说Junit是xunit家族中的一员. unit <- unit test case,即单元测试用例. Junit = java uni ...
- springboot 如何操作redis
1.首先应该引入 依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...
- Mapper动态代理方式
开发规范 Mapper接口开发方法只需要程序员编写Mapper接口(相当于Dao接口),由Mybatis框架根据接口定义创建接口的动态代理对象,代理对象的方法体同Dao接口实现类方法. Mapper接 ...
- python3 阿里云控制SLB权重
一.配置好RAM账号的权限(SLB管理权限) 二.安装依赖 pip3 install aliyun-python-sdk-slb pip3 install aliyun-python-sdk-core ...
- centso7 安装redmine
一.安装rvm ###安装rvm gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D3 ...
- maven(win10)配置完环境变量后无法识别mvn -v命令
第一步:http://maven.apache.org/download.cgi官网下载 第二步:把压缩包解压缩到不含中文和空格的目录下 第三步:新建MAVEN_HOME环境变量,值为maven解压缩 ...
- Python——列表操作
一.列表中所有元素出现的次数,并输出为字典模式 def count_list(list): b_list = {} for i in set(list): b_list[i] = list.count ...
- <resultMap>中 <collection>的使用
public class Question implements Serializable { private int id; //问题Id private int accountId; //用户id ...
- Linux压缩和解压命令
zip命令: 压缩 :zip -r files.zip fileFolder 解压:unzip files.zip tar命令: 压缩:tar -cvf files.tar fileFolder 解压 ...
- Jarvis OJ A Piece Of Cake
看图片的隐写术自闭,本来想看一看jarvisoj 的basic放松一下心情,结果一道题就做了一晚上qwq 首先看到这道题的时候想到的是凯撒密码(这其实是Google之后才知道这个名字的)枚举了26种位 ...