首页 > 代码库 > bzoj2419
bzoj2419
http://www.lydsy.com/JudgeOnline/problem.php?id=2419
∑Ui?UjRi,j=0∑Ui?UjRi,j=0
∑U1?UjR1,j=1∑U1?UjR1,j=1
∑Un?UjRi,n=?1∑Un?UjRi,n=?1
Un=0
这就是方程了。。。但是代码有点不理解
#include<bits/stdc++.h> using namespace std; const int N = 510; double a[N][N], g[N][N]; int n, m; void build() { for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) a[i][i] += g[i][j], a[i][j] -= g[i][j]; a[1][n + 1] = 1.0; a[n][n + 1] = -1.0; a[n][n] += 1.0; } void gauss_jordan() { for(int now = 1; now <= n; ++now) { int x = now; for(int i = now + 1; i <= n; ++i) if(fabs(a[i][now]) > fabs(a[x][now])) x = i; for(int i = 1; i <= n + 1; ++i) swap(a[now][i], a[x][i]); double t = a[now][now]; for(int i = now; i <= n + 1; ++i) a[now][i] /= t; for(int i = 1; i <= n; ++i) if(i != now) { double t = a[i][now]; for(int j = now; j <= n + 1; ++j) a[i][j] -= t * a[now][j]; } } } int main() { while(scanf("%d%d", &n, &m) != EOF) { memset(a, 0, sizeof(a)); memset(g, 0, sizeof(g)); for(int i = 1; i <= m; ++i) { int u, v; double r; scanf("%d%d%lf", &u, &v, &r); if(u == v) continue; g[u][v] += 1.0 / r; g[v][u] += 1.0 / r; } build(); gauss_jordan(); printf("%.2f\n", a[1][n + 1]); } return 0; }
bzoj2419
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。