HDU5036 Explosion(期望&&bitset)
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <bitset>
using namespace std; #define maxn 1005 bitset<1100> b[maxn];
int n; int main()
{
int T;cin>>T;int ca=0;
while(T--){
scanf("%d",&n);
for(int i=1;i<=n;++i) b[i].reset();
for(int i=1;i<=n;++i){
int num;scanf("%d",&num);
b[i][i]=true;
while(num--){
int tmp;
scanf("%d",&tmp);
b[i][tmp]=true;
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
if(b[j][i]) b[j]|=b[i];
}
}
double ans=0;
for(int i=1;i<=n;++i){
int cnt=0;
for(int j=1;j<=n;++j){
if(b[j][i]) ++cnt;
}
ans+=1.0/cnt;
}
printf("Case #%d: %.5lf\n",++ca,ans);
}
return 0;
}
HDU5036 Explosion(期望&&bitset)的更多相关文章
- HDU5036 Explosion(期望 bitset)
题意 题目链接 Sol 和cf上的一道题几乎一摸一样 首先根据期望的线性性,可以转化为求每个点的期望打开次数,又因为每个点最多会被打开一次,只要算每个点被打开的概率就行了 设\(anc[i]\)表示\ ...
- hdu 5036 Explosion(概率期望+bitset)
Problem Description Everyone knows Matt enjoys playing games very much. Now, he to N. Input The firs ...
- HDU 5036 Explosion (传递闭包+bitset优化)
<题目链接> 题目大意: 一个人要打开或者用炸弹砸开所有的门,每个门后面有一些钥匙,一个钥匙对应一个门,告诉每个门里面有哪些门的钥匙.如果要打开所有的门,问需要用的炸弹数量为多少. 解题分 ...
- hdu5036 Explosion 传递闭包
大哲哥的讲课内容 根据期望的线性性,得到总期望为各个点被轰的概率(不会证,好像是这样吧) 传递闭包解决出每个点的祖先(能到达它的点)就能算概率了 bitset能贡献1/w的复杂度,而且导致Floyd只 ...
- HDU5036(bitset加速传递闭包+期望)
HDU5036 题解 题目链接 思路: 求出破坏or打开所有门所需要的期望炮弹数量,那么根据期望的线性性质,我们可以求出每一个门的期望值最后累加起来就行了. 我们最后的目标就是求对于一个门\(i\), ...
- 概率期望+闭包+bitset优化——hdu5036
我们首先得到: 暴力打开这个箱子,能够开那些箱子.这个可以用bitset来进行状态压缩. 用闭包传递来解决这一步 然后,对于每个箱子,我们考虑有多少种方法,使:暴力打开某些箱子,同时能 ...
- Hdu 5036-Explosion 传递闭包,bitset,期望/概率
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5036 Explosion Time Limit: 6000/3000 MS (Java/Others) ...
- hdu 5036 Explosion bitset优化floyd
http://acm.hdu.edu.cn/showproblem.php?pid=5036 题意就是给定一副有向图,现在需要走遍这n个顶点,一开始出发的顶点是这n个之中的随便一个. 如果走了1,那么 ...
- NBUT 1635 Explosion(最小顶点覆盖)
[1635] Explosion 时间限制: 10000 ms 内存限制: 65535 K 问题描述 there is a country which contains n cities connec ...
随机推荐
- JS — 实现简单的数字时钟
js实现简单的数字时钟 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...
- JZOJ 5347. 遥远的金字塔
Description Input Output Sample Input 5 3 1 6 1 5 3 5 4 4 4 4 Sample Output 15 Data Constraint 做法: 其 ...
- Elizabeth Taylor【伊丽莎白·泰勒】
Elizabeth Taylor People fell in love with Elizabeth Taylor in 1944, when she acted in the movie Nati ...
- HDU - 5017 Ellipsoid(模拟退火)
题意 给一个三维椭球面,求球面上距离原点最近的点.输出这个距离. 题解 模拟退火. 把\(z = f(x, y)\)函数写出来,这样通过随机抖动\(x\)和\(y\)坐标就能求出\(z\). 代码 / ...
- 测试环境docker化(一)—基于ndp部署模式的docker基础镜像制作
本文来自网易云社区 作者:孙婷婷 背景 我所在测试项目组目前的测试环境只有一套,在项目版本迭代过程中,开发或产品偶尔会在测试环境进行数据校验,QA人数在不断增加,各个人员在负责不同模块工作时也会产生脏 ...
- Leetcode 553.最优除法
最优除法 给定一组正整数,相邻的整数之间将会进行浮点除法操作.例如, [2,3,4] -> 2 / 3 / 4 . 但是,你可以在任意位置添加任意数目的括号,来改变算数的优先级.你需要找出怎么添 ...
- sql2005 和sql2008 同时安装
Hkey_local_machine\Software\Wow6432Node\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM 中的ShellSEM重 ...
- 替换掉 in的like操作
select * from t_unit where '410300060025,410300004005,410300998851,' like '%'+ltrim(rtrim(unitcode)) ...
- Unity 脚本<1>
RaycastHit2D hit = Physics2D.Linecast(targetPosition, targetPosition + new Vector2(x, y)); 猜测是lineca ...
- Mysql实战之高可用HMA
author:JevonWei 版权声明:原创作品 主节点高可用 MHA是一款开源的MySQL的高可用程序,他为MySQL主从复制架构提供了automating master failover功能.M ...