链接:

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. jvm的学习笔记:二、类的初始化,代码实战(3)

    首次主动此用导致类的初始化 MyParent4 myParent4 = new MyParent4(); MyParent4 myParent5 = new MyParent4(); 输出: MyPa ...

  2. mysql数据的备份

    一.备份方式 1.备份:逻辑备份(mysqldump,mydumper).物理备份(xtrabackup.tar.cp.rsync)    2.冗余:主备模式.数据库集群 二.备份对象 1.数据(库. ...

  3. centos 6.5安装erlang和RabbitMQ

    一.安装erlang 1.下载erlang源码 git clone https://github.com/erlang/otp.git 2.编译并安装erlang cd otp ./otp_build ...

  4. 【Linux开发】【DSP开发】Linux设备驱动之——PCI 总线

    PCI总线概述  随着通用处理器和嵌入式技术的迅猛发展,越来越多的电子设备需要由处理器控制.目前大多数CPU和外部设备都会提供PCI总线的接口,PCI总线已成为计算机系统中一种应用广泛.通用的总线标准 ...

  5. POP与OOP编程模式对比

    面向过程:(procedure oriented programming 即:POP) 代表:C/C++ 向过程程序设计,它是以功能为中心来进行思考和组织的一种编程方式,强调的是系统的数据被加工和处理 ...

  6. 2.更新YUM源

    查看本地源 先删除本地所有源 下载源仓库文件,xxx.repo curl -o /etc/yum.repos.d/ali.repo http://mirrors.aliyun.com/repo/Cen ...

  7. .Net Core 3.0使用Grpc进行远程过程调用

    因为.Net Core3.0已经把Grpc作为一等臣民了,作为爱好新技术的我,当然要尝鲜体验一下了,当然感觉是Grpc作为跨语言的产品做的相当好喽,比起Dubbo这种的,优势和劣势还是比较明显的. 我 ...

  8. win10 远程桌面ubuntu16

    一. 软件安装 1.1. 打开终端,安装xrdp,vncserver sudo apt-get install xrdp vnc4server xbase-clients 1.2. desktop s ...

  9. # 「NOIP2010」关押罪犯(二分图染色+二分答案)

    「NOIP2010」关押罪犯(二分图染色+二分答案) 洛谷 P1525 描述:n个罪犯(1-N),两个罪犯之间的仇恨值为c,m对仇恨值,求怎么分配使得两件监狱的最大仇恨值最小. 思路:使最大xxx最小 ...

  10. 数据库or、in、<>、>=、<=、butween区别

    操作前先关闭数据库缓存 #创建测试的test表 DROP TABLE IF EXISTS test; CREATE TABLE test( `id` ) NOT NULL, `name` ) DEFA ...