首页 技术 正文
技术 2022年11月16日
0 收藏 503 点赞 2,331 浏览 1484 个字

题面

题解

图上的期望大部分是\(dp\),无向图的期望大部分是高斯消元

设\(f[i]\)表示走到点\(i\)的期望,\(d[i]\)表示\(i\)的度,\(to(i)\)表示\(i\)能到达的点集

所以\(f[i] = \sum\limits_{x \in to(i)} f[x] / d[x]\)

然后每个点能够列出这样的方程,直接高斯消元就可以了

代码

#include<bits/stdc++.h>
#define RG register
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;inline int read()
{
int data = 0, w = 1;
char ch = getchar();
while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if(ch == '-') w = -1, ch = getchar();
while(ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
return data*w;
}const int maxn(510), maxm(250100);
struct edge { int next, to; } e[maxm << 1];
int head[maxn], e_num;
inline void add_edge(int from, int to) { e[++e_num] = {head[from], to}; head[from] = e_num; }
double a[maxn][maxn], ans[maxm], Ans, deg[maxn];
int n, m, from[maxm], to[maxm];inline void Gauss()
{
for(RG int i = 1, k = i; i <= n; i++, k = i)
{
for(RG int j = k + 1; j <= n; j++) if(fabs(a[k][i]) < fabs(a[j][i])) k = j;
swap(a[i], a[k]);
for(RG int j = i + 1; j <= n + 1; j++) a[i][j] /= a[i][i];
a[i][i] = 1.;
for(RG int j = 1; j <= n; j++)
{
if(i == j) continue;
for(RG int k = i + 1; k <= n + 1; k++) a[j][k] -= a[j][i] * a[i][k];
a[j][i] = 0.;
}
}
}int main()
{
n = read(); m = read();
for(RG int i = 1; i <= m; i++)
{
from[i] = read(); to[i] = read();
add_edge(from[i], to[i]); deg[from[i]] += 1.;
add_edge(to[i], from[i]); deg[to[i]] += 1.;
}
for(RG int i = 1; i < n; i++)
{
for(RG int j = head[i]; j; j = e[j].next) if(e[j].to != n) a[i][e[j].to] += -1. / deg[e[j].to];
a[i][i] = 1;
}
a[n][n] = 1;
a[1][n + 1] = 1; Gauss();
for(RG int i = 1; i <= m; i++)
ans[i] = ((from[i] == n) ? 0 : a[from[i]][n + 1] / deg[from[i]]) + ((to[i] == n) ? 0 : a[to[i]][n + 1] / deg[to[i]]);
sort(ans + 1, ans + m + 1);
for(RG int i = 1; i <= m; i++) Ans += (m - i + 1) * ans[i];
printf("%.3lf\n", Ans);
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898