迪杰斯特拉最短路径。

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. [ios2] CABasicAnimation【转】

    caanimation 整理了解  http://geeklu.com/2012/09/animation-in-ios/ 几个可以用来实现热门APP应用PATH中menu效果的几个方法 +(CABa ...

  2. C#Windows Form简易计算器实现(中)

    昨天花了一天的时间弄计算器.也算是做出来了,还是简易的(怀疑猿生!!).在此先感谢昨天被我骚扰的朋友. 先贴一张界面看看 其实健壮性还是挺差的,用户体验也是极差的.比如说用户输入了不合理运算式子,我就 ...

  3. 遍历HashMap的最佳方式

    public static void printMap(Map mp) { Iterator it = mp.entrySet().iterator(); while (it.hasNext()) { ...

  4. ssh爆破脚本

    前些天,基友发我一个ssh爆破工具,看起来很吊的样子.然后我就无聊自己写了个py脚本的. 单线程:慢成狗----- #coding:utf-8 #author:jwong import threadi ...

  5. 解决 maven项目问题 An error occurred while filtering resources

    解决方法: Maven -> Update Project.

  6. webservice(二)

    ---摘自网络,感谢提供者 WsExplorer和Tcp/Ip Monitor工具本身就存在于eclipse和MyEclipse中 使用工具的原因: 1.  使用工具可以更好的了解WebService ...

  7. 8个不可不知的Mac OS X专用命令行工具【转】

    OS X的终端下通用很多Unix的工具和脚本.如果从Linux迁移到OS X会发现很多熟悉的命令和脚本工具,其实并没有任何区别. 但是OS X也提供了很多其他系统所没有的特别的命令行工具.我们推荐8个 ...

  8. C# IIS7.0+ Web.Config 配置Session过期时间

    1. 2. 3. <sessionState mode="InProc" timeout="120"></sessionState>

  9. Duilib使用wke显示echarts

    不得不说wke是个简洁好用的浏览器内核.网上很多大神已经把wke嵌入到duilib中了,先感谢他们辛勤的工作.这里通过wke吧C++的数据在ECharts上美观的显示出来.借鉴前人,将ECharts进 ...

  10. ECStore图片存储采用阿里云OSS(图片存储)服务

    主要功能:ECStore图片存储采用阿里云OSS(图片存储)服务   适用版本:ECStore 授权方式:授权域名使用,付费插件 联系方式: QQ 275553385  mail: jimingson ...