迪杰斯特拉最短路径。

1.every city must wait till all the goods arrive, and then transport the arriving goods together with its own goods to the next city.  这个条件貌似可以忽略掉。

2.One city can only transport the goods to one city.  这个条件貌似也可以忽略掉,是一定的。

例如:A物品和B物品在不同的城市,他们都往X城市运输,然而X城市到首都的最少损失的路必定只有一条的,所以2条件可以忽略。至于1条件,等和不等好像也没什么区别...... = =!

综上所述:就是每个物品只管自己运输,算最短路,每条路的权值就是比例,算出每个城市到首都损耗最少的路即可。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = ;
double weight[maxn], ratio[maxn][maxn], e[maxn];
int s[maxn];
int main()
{
int n, m, i, j, u, v, ii;
double cc;
while (~scanf("%d%d", &n, &m))
{
memset(s, , sizeof(s));
memset(ratio, , sizeof(ratio));
for (i = ; i <= n - ; i++) scanf("%lf", &weight[i]);
for (i = ; i <= m; i++)
{
scanf("%d%d%lf", &u, &v, &cc);
cc = - cc;
if (cc > ratio[u][v])
{
ratio[u][v] = cc;
ratio[v][u] = cc;
}
}
for (i = ; i <= n; i++) e[i] = ratio[n][i];
e[n] = ; s[n] = ;
for (ii = ; ii < n; ii++)
{
double maxn = -;
int flag = , x;
for (i = ; i <= n; i++)
{
if (!s[i] && (maxn< || maxn<e[i]))
{
flag = ;
maxn = e[i];
x = i;
}
}
if (!flag) break;
s[x] = ;
for (i = ; i <= n; i++)
if (!s[i] && ratio[x][i] != && e[x] * ratio[x][i] > e[i])
e[i] = e[x] * ratio[x][i];
}
double anss = ;
for (i = ; i < n; i++) anss = anss + e[i] * weight[i];
printf("%.2f\n", anss);
}
return ;
}

ZOJ 1655 FZU 1125 Transport Goods的更多相关文章

  1. ZOJ - 1655 Transport Goods(单源最长路+迪杰斯特拉算法)

    题目: 有N-1个城市给首都(第N个城市)支援物资,有M条路,走每条路要耗费一定百分比(相对于这条路的起点的物资)的物资.问给定N-1个城市将要提供的物资,和每条路的消耗百分比.求能送到首都的最多的物 ...

  2. ZOJ1655 Transport Goods(Floyd)

    利用Floyd的DP状态转移方程. #include<cstdio> #include<cstring> #include<queue> #include<a ...

  3. zoj 1655 单源最短路 改为比例+最长路

    http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=655 没有理解清题意就硬套模板.所以WA了好几次. 解析看我的还有一篇http ...

  4. Goods transportation

    Goods transportation time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation 动态规划

    E. Goods transportation 题目连接: http://codeforces.com/contest/724/problem/E Description There are n ci ...

  6. [codeforces724E]Goods transportation

    [codeforces724E]Goods transportation 试题描述 There are n cities located along the one-way road. Cities ...

  7. Minimum Cost(最小费用最大流)

    Description Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his s ...

  8. POJ 2516 Minimum Cost (费用流)

    题面 Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area ...

  9. POJ 2516 Minimum Cost (网络流,最小费用流)

    POJ 2516 Minimum Cost (网络流,最小费用流) Description Dearboy, a goods victualer, now comes to a big problem ...

随机推荐

  1. [JAVA] 学java必看书籍

    <java编程思想>,<Effective Java>,<JVM虚拟机规范>     <Java核心技术>    <Java Web开发技术大全& ...

  2. HDU 4777 Rabbit Kingdom

    素因子分解,树状数组.$ACM/ICPC$ $2013$杭州区域赛$H$题. 首先需要处理出数字$a[i]$左边最远到$L[i]$,右边最远到$R[i]$区间内所有数字都与$a[i]$互质. 那么对于 ...

  3. html5 canvas的教程

    原文地址:http://www.cnblogs.com/tim-li/archive/2012/08/06/2580252.html 原作很强悍 导航 前言 基本知识 绘制矩形 清除矩形区域 圆弧 路 ...

  4. Kattis - Peragrams

    Peragrams Photo by Ross Beresford Per recently learned about palindromes. Now he wants to tell us ab ...

  5. mysql添加mcafee 审计插件

    插件源码地址https://github.com/mcafee/mysql-audit插件安装方法https://github.com/mcafee/mysql-audit/wiki/Installa ...

  6. eclipse里xml提示包名的插件——Rinzo

    1.Rinzo简介 在官方网站上的介绍到,Rinzo是一款Eclipse的XML编辑器,可以使在处理XML文件时变得简洁高效.与一般的XML文件相比,具有以下特点: l 自动显示DTD或Schema里 ...

  7. centos下安装Jenkins轻松搞定

    jenkins安装步骤如下: 命令:yum -y list java* yum -y install java-1.7.0-openjdk.x86_64                         ...

  8. 【原生js】js动态添加dom,如何绑定事件

    首先要明白浏览器在加载页面的时候是按顺序来加载的,这样以来就很清楚了,js动态添加dom以后,这些dom并没有绑定事件,这个时候最简单的一个办法就是:将绑定事件的方法封装到一个函数A中,在动态添加完d ...

  9. 著名清理软件(CCleaner) 5.24.5841 中文版

    软件名称: 著名清理软件(CCleaner) 软件语言: 多国语言 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 5.7MB 图片预览: 软件简介: CCleaner的体积小, ...

  10. 初遇locust

    大概有四个月没有用过PYTHON的我. 今天差点都不知道怎么运行了. 说起来真是丢人呐. 幸好还是存留着一点点印象,再加上看了一下以前写的几篇文章, 还是比较快的想起来了.不然真的是要崩溃了. 刚开始 ...