hdu 5036 Explosion(概率期望+bitset)

Problem Description
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 1 to N.

 

Input
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<=1000) indicating the number of rooms. 

The following N lines corresponde to the rooms from 1 to N. Each line begins with an integer k (0<=k<=N) indicating the number of keys behind the door. Then k integers follow corresponding to the rooms these keys can open.

 

 

Output
For each test case, output one line "Case #x: y", where x is the case number (starting from 1), y is the answer which should be rounded to 5 decimal places.

 

 
Sample Input
2
3
1 2
1 3
1 1
3
0
0
0

 

 

 

Sample Output
Case #1: 1.00000 
Case #2: 3.00000

 

 

 

Source
 
题意:
一个人要打开或者用炸弹砸开所有的门,每个门里面有一些钥匙,一个钥匙对应一个门,有了一个门的钥匙就能打开相应的门,告诉每个门里面有哪些门的钥匙,问需要用的炸弹为多少。
 
思路:
考虑每个点需要用炸弹打开的概率,那么所有点的概率之和就是解。 每个点 v 需要用炸弹打开的概率是 1/S, S是u(u->v联通)的数量, 然后就变成求这个图的传递闭包了,用bitset优化。为什么是1/S呢,因为这S个门里面必定要用一个炸弹砸开,而砸v的概率为1/S。
 
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<stdlib.h>
 7 #include<bitset>
 8 using namespace std;
 9 #define N 1006
10 int n;
11 bitset<N> bs[N];
12 int main()
13 {
14    int t;
15    int ac=0;
16    scanf("%d",&t);
17    while(t--){
18       scanf("%d",&n);
19       for(int i=0;i<N;i++){
20          bs[i].reset();
21          bs[i][i]=true;
22       }
23       for(int i=0;i<n;i++){
24          int k;
25          scanf("%d",&k);
26          for(int j=0;j<k;j++){
27             int x;
28             scanf("%d",&x);
29             x--;
30             bs[i][x]=true;
31          }
32       }
33       for(int j=0;j<n;j++){
34          for(int i=0;i<n;i++){
35             if(bs[i][j]){
36                bs[i] |= bs[j];
37             }
38          }
39       }
40       double ans=0;
41       for(int j=0;j<n;j++){
42          int cnt=0;
43          for(int i=0;i<n;i++){
44             if(bs[i][j]){
45                cnt++;
46             }
47          }
48          ans+=1.0/cnt;
49       }
50       printf("Case #%d: %.5lf\n",++ac,ans);
51    }
52    return 0;
53 }
View Code

 

Recommend
内容概要:《中文大模型基准测评2025年上半年报告》由SuperCLUE团队发布,详细评估了2025年上半年中文大模型的发展状况。报告涵盖了大模型的关键进展、国内外大模型全景图及差距、专项测评基准介绍等。通过SuperCLUE基准,对45个国内外代表性大模型进行了六大任务(数学推理、科学推理、代码生成、智能体Agent、精确指令遵循、幻觉控制)的综合测评。结果显示,海外模型如o3、o4-mini(high)在推理任务上表现突出,而国内模型如Doubao-Seed-1.6-thinking-250715在智能体Agent和幻觉控制任务上表现出色。此外,报告还分析了模型性价比、效能区间分布,并对代表性模型如Doubao-Seed-1.6-thinking-250715、DeepSeek-R1-0528、GLM-4.5等进行了详细介绍。整体来看,国内大模型在特定任务上已接近国际顶尖水平,但在综合推理能力上仍有提升空间。 适用人群:对大模型技术感兴趣的科研人员、工程师、产品经理及投资者。 使用场景及目标:①了解2025年上半年中文大模型的发展现状与趋势;②评估国内外大模型在不同任务上的表现差异;③为技术选型和性能优化提供参考依据。 其他说明:报告提供了详细的测评方法、评分标准及结果分析,确保评估的科学性和公正性。此外,SuperCLUE团队还发布了多个专项测评基准,涵盖多模态、文本、推理等多个领域,为业界提供全面的测评服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值