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优化)
<题目链接> 题目大意: 一个人要打开或者用炸弹砸开所有的门,每个门后面有一些钥匙,一个钥匙对应一个门,告诉每个门里面有哪些门的钥匙.如果要打开所有的门,问需要用的炸弹数量为多少. 解题分 ...
随机推荐
- kubernetes常用命令
#.查询信息 kubectl get [需要查询的服务] node 节点componentstatuses 简写 cs 组件状态namespaces 简写 ns 名命空间pod pod信息 添加 ...
- Linux在shell中进入python敲方向键出现「^[[C^[[D」的解决办法
安装yum -y install readline-devel,然后在重新编译python
- Chrome 75 & lazy-loading
Chrome 75 & lazy-loading https://addyosmani.com/blog/lazy-loading/ https://chromestatus.com/feat ...
- font_awesome的icon库的使用
1.使用cdn引入font_awesome图标库的css文件 例如:index.htm <html><head><title>font_awesome test&l ...
- supervisor /var/run/supervisor/supervisor.sock not found 或者/tmp/supervisor.sock not found
刚按装完supervisor,这时候用supervisorctr -c supervisor.conf 会报错: /var/run/supervisor/supervisor.sock not fou ...
- 怎样利用ADO中的adoquery进行缓存更新?????(100分)
我用BDE时,用query与updatesql相结合进行缓存更新,但是在ADO中没有updatesql,只有用adoquery,在DBGRID中,用CANCELUPADTE,只能取消一条记录,烦恼不已 ...
- 三、Docker网络
一.查看8001端口是否开启处监听状态 netstat -apnl | grep 8001 二.使用brctl show可以看到虚拟机的网络关系 brctl show docker每新建一个conta ...
- vue 子组件修改父组件传来的props值,报错
vue不推荐直接在子组件中修改父组件传来的props的值,会报错 [Vue warn]: Avoid mutating a prop directly since the value will be ...
- js定时函数,定时改变字体的大小
<html> <head> </head> <body> <div id="d"> js控制字体大小 </div& ...
- Jarvis OJ A Piece Of Cake
看图片的隐写术自闭,本来想看一看jarvisoj 的basic放松一下心情,结果一道题就做了一晚上qwq 首先看到这道题的时候想到的是凯撒密码(这其实是Google之后才知道这个名字的)枚举了26种位 ...