链接:

https://nanti.jisuanke.com/t/41402

题意:

To seek candies for Maomao, Dudu comes to a maze. There are nn rooms numbered from 11 to nn and mm undirected roads.

There are two kinds of rooms in the maze -- candy room and monster room. There is one candy in each candy room, and candy room is safe. Dudu can take the only candy away when entering the room. After he took the candy, this candy room will be empty. A empty room is also safe. If Dudu is in safe, he can choose any one of adjacent rooms to go, whatever it is. Two rooms are adjacent means that at least one road connects the two rooms.

In another kind of rooms, there are fierce monsters. Dudu can't beat these monsters, but he has a magic portal. The portal can show him a randomly chosen road which connects the current room and the other room.

The chosen road is in the map so Dudu know where it leads to. Dudu can leave along the way to the other room, and those monsters will not follow him. He can only use the portal once because the magic energy is not enough.

Dudu can leave the maze whenever he wants. That's to say, if he enters a monster room but he doesn't have enough energy to use the magic portal, he will choose to leave the maze immediately so that he can save the candies he have. If he leave the maze, the maze will never let him in again. If he try to fight with the monsters, he will be thrown out of the maze (never let in, of course). He remembers the map of the maze, and he is a clever guy who can move wisely to maximum the expection of candies he collected.

Maomao wants to know the expected value of candies Dudu will bring back. Please tell her the answer. He will start his adventure in room 1, and the room 1 is always a candy room. Since there may be more than one road connect the current room and the room he wants to go to, he can choose any of the roads.

思路:

将所有连起来的点并且中间没有怪物的点连起来, 1的联通必选, 在从1能到的怪物的点挨个枚举, 选一个期望最大的点即可.

代码:

#include <bits/stdc++.h>
using namespace std; const int MAXN = 1e5+10;
vector<int> G[MAXN];
int Fa[MAXN], Sum[MAXN];
bool Vis[MAXN];
int n, m, k; int GetF(int x)
{
if (Fa[x] == x)
return x;
Fa[x] = GetF(Fa[x]);
return Fa[x];
} int main()
{
int t;
scanf("%d", &t);
while (t--)
{
scanf("%d%d%d", &n, &m, &k);
for (int i = 1;i <= n;i++)
Fa[i] = i, Sum[i] = 1, Vis[i] = false, G[i].clear();
int u, v;
for (int i = 1;i <= m;i++)
{
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
for (int i = 1;i <= k;i++)
{
scanf("%d", &u);
Vis[u] = true;
Sum[u] = 0;
}
for (int i = 1;i <= n;i++)
{
for (int j = 0;j < G[i].size();j++)
{
int a = i, b = G[i][j];
if (Vis[a] || Vis[b])
continue;
a = GetF(a);
b = GetF(b);
if (a != b)
{
if (a == 1)
{
Fa[b] = a;
Sum[a] += Sum[b];
}
else
{
Fa[a] = b;
Sum[b] += Sum[a];
}
}
}
}
double res = 0;
for (int i = 1;i <= n;i++)
{
if (!Vis[i])
continue;
bool Flag = false;
for (int j = 0;j < G[i].size();j++)
{
if (GetF(G[i][j]) == 1)
{
Flag = true;
break;
}
}
if (!Flag)
continue;
double tmp = 0;
for (int j = 0;j < G[i].size();j++)
{
int node = GetF(G[i][j]);
if (node != 1)
{
// cout << Sum[node] << ' ' << G[i].size() << endl;
tmp += (Sum[node]*1.0)/(int)G[i].size();
}
}
res = max(res, tmp);
}
res += Sum[1];
printf("%.6lf\n", res);
} return 0;
}

2019ICPC沈阳网络赛-B-Dudu's maze(缩点)的更多相关文章

  1. 2019沈阳网络赛B.Dudu's maze

    https://www.cnblogs.com/31415926535x/p/11520088.html 啊,,不在状态啊,,自闭一下午,,都错题,,然后背锅,,,明明这个简单的题,,, 这题题面不容 ...

  2. 2019icpc沈阳网络赛 D Fish eating fruit 树形dp

    题意 分别算一个树中所有简单路径长度模3为0,1,2的距离和乘2. 分析 记录两个数组, \(dp[i][k]\)为距i模3为k的子节点到i的距离和 \(f[i][k]\)为距i模3为k的子节点的个数 ...

  3. 2019ICPC沈阳网络赛-D-Fish eating fruit(树上DP, 换根, 点分治)

    链接: https://nanti.jisuanke.com/t/41403 题意: State Z is a underwater kingdom of the Atlantic Ocean. Th ...

  4. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  5. 线段树+单调栈+前缀和--2019icpc南昌网络赛I

    线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is eq ...

  6. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  7. 沈阳网络赛 F - 上下界网络流

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  8. 沈阳网络赛J-Ka Chang【分块】【树状数组】【dfs序】

    Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, ...

  9. 沈阳网络赛D-Made In Heaven【k短路】【模板】

    One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci ...

随机推荐

  1. 【Aizu - 0558】Cheese(bfs)

    -->Cheese 原文是日语,这里就写中文了 Descriptions: 在H * W的地图上有N个奶酪工厂,每个工厂分别生产硬度为1-N的奶酪.有一只老鼠准备从出发点吃遍每一个工厂的奶酪.老 ...

  2. 1.docker 慕课入门

    本文是学习慕课网的实战https://www.imooc.com/learn/824  同时结合菜鸟教程的思想https://www.runoob.com/docker/docker-architec ...

  3. 关于js查找和筛选和循环的几种方式

    find(); find() 方法返回通过测试(函数内判断)的数组的第一个元素的值. find() 方法为数组中的每个元素都调用一次函数执行: 当数组中的元素在测试条件时返回 true 时, find ...

  4. aws和ufile挂载数据盘EBS

    aws的话挂载的ebs需要格式化,参考:https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/UserGuide/ebs-using-volumes.html ...

  5. 2019牛客暑期多校训练营(第二场)-E MAZE

    题目链接:https://ac.nowcoder.com/acm/contest/882/E 题意:n×m的矩阵,0表示可以走,1表示墙,不能通过.有q中操作,一种是改变坐标(x,y)的状态,一种是询 ...

  6. 阿里云服务器挖矿脚本bioset攻击解决

    1.问题出现 一大早刚起床,阿里云就给我发了一条短信,提醒我服务器出现紧急安全事件:挖矿程序 阿里云“贴心”地提供了解决方法,不过需要购买企业版的安全服务,本着能自己动手就不花钱原则自己搞了起来 于是 ...

  7. PreparedStatement 以及事务的注意事项

    a).PreparedStatement 可以进行批量操作,但是与Statement有一定的区别 1. Statement可以进行不同sql语句的批量操作 即可以同时进行 crud 操作. Strin ...

  8. JavaSSM框架精选50道面试题

    JavaSSM框架精选50道面试题 2019年02月13日 19:04:43 EerhtSedah 阅读数 7760更多 分类专栏: 面试题   版权声明:本文为博主原创文章,遵循CC 4.0 BY- ...

  9. spring boot 配置文件动态更新原理 以Nacos为例

    配置文件的动态更新 通常获取配置文件的方式 1, @Value 2. @ConfigurationProperties(Prefix) 如果是在运行时要动态更新的话, 第一种方式要在bean上加@Re ...

  10. 第二章 单表查询 T-SQL语言基础(3)

    单表查询(3) 2.6 处理字符数据 字符数据的查询处理,内容包括:类型,排序规则,运算符和函数,以及模式匹配. 2.6.1 数据类型 SQL Server支持两种字符数据类型----普通字符和Uni ...