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 = ;
double a[N][N], g[N][N];
int n, m;
void build()
{
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
a[i][i] += g[i][j], a[i][j] -= g[i][j];
a[][n + ] = 1.0;
a[n][n + ] = -1.0;
a[n][n] += 1.0;
}
void gauss_jordan()
{
for(int now = ; now <= n; ++now)
{
int x = now;
for(int i = now + ; i <= n; ++i) if(fabs(a[i][now]) > fabs(a[x][now])) x = i;
for(int i = ; i <= n + ; ++i) swap(a[now][i], a[x][i]);
double t = a[now][now];
for(int i = now; i <= n + ; ++i) a[now][i] /= t;
for(int i = ; i <= n; ++i) if(i != now)
{
double t = a[i][now];
for(int j = now; j <= n + ; ++j) a[i][j] -= t * a[now][j];
}
}
}
int main()
{
while(scanf("%d%d", &n, &m) != EOF)
{
memset(a, , sizeof(a));
memset(g, , sizeof(g));
for(int i = ; 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[][n + ]);
}
return ;
}
bzoj2419的更多相关文章
随机推荐
- Spider-scrapy 中的 xpath 语法与调试
把setting中的机器人过滤设为False ROBOTSTXT_OBEY = False 1 语法 artcile 选取所有子节点 /article 选取根元素 artile article/a 选 ...
- 【BZOJ 1003】[ZJOI2006]物流运输(Dijkstra+DP)
题链 http://www.lydsy.com/JudgeOnline/problem.php?id=1003 Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n ...
- STM32F407 GPIO 库函数编程套路(led与beep总结) 个人笔记
本文由正点原子STM32F407探索者开发板的led和beep实验,总结了gpio编程的套路. 下文中以hardware 来称呼可能的硬件外设,如led或beep等. 新建项目后主要用到三个文件:ha ...
- 全文搜索(A-2)-推荐算法
一般来说推荐算法分为两类. 基于内容过滤的推荐: 基于协同过滤的推荐: 基于内容过滤的推荐,基于特征码描述项目. 协同过滤算法的设计基于一个假设,“和目标用户相似度高的用户,其感兴趣的物品目标用户也会 ...
- CookiesReader
CookiesReader "use strict"; /** * * @author xgqfrms * @license MIT * @copyright xgqfrms * ...
- Python模块:shutil、序列化(json&pickle&shelve)、xml
shutil模块: 高级的 文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fscr,fdst [, length]) # 将文件内容拷贝到另一个文件中 import shu ...
- 在workbench中导入.sql文件!(导入数据库文件)
第一步,登陆mysql workbench 第二步,打开自己的数据 ,此处默认(root) 打开数据库后页面 : 第三步,新建一个schema ,随便给个名字,这里起名为test : 可以看到test ...
- [转]MySQL5字符集支持及编码研究
前言 在更新数据库时,有时会遇到这样的错误: Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COER ...
- 【ZJOI2017 Round1练习&BZOJ5350】D5T1 masodik(DP,斜率优化)
题意:你要从(0,0)点走到(n,m), 每次只能往 x 轴或者 y 轴正方向移动一个单位距离.从(i,j)移动到(i,j+1)的代价为 ri,从(i,j)移动到(i+1,j)的代价为 cj. 求最小 ...
- codevs3728 联合权值
题目描述 Description 输入描述 Input Description 输出描述 Output Description 样例输入 Sample Input 样例输出 Sample Output ...