迪杰斯特拉最短路径。

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. spring-mvc + shiro框架整合(sonne_game网站开发04)

    这篇文章讲的内容是在之前spring + mybatis + spring-mvc + freemarker框架整合的代码的基础上.有需要的可以看看我博客的前两篇文章. 另外,本文章所讲相关所有代码都 ...

  2. (七)第一个python程序!

    这是对我自己来说比较有仪式的一篇随笔记录,说了那么多,开始第一个pyhton小程序吧! 首先找一个版本比较新的Linux系统, 执行Python –V 查看一下你的Python版本: # python ...

  3. [z] .net与java建立WebService再互相调用

    http://blog.csdn.net/yenange/article/details/5824967 : .net建立WebService,在Java中调用. 1.在vs中新建web 简单修改一下 ...

  4. tab切换☆☆☆☆☆

    <!doctype html><html lang="en"><head> <meta charset="UTF-8" ...

  5. centos 安装apache activemq

    安装说明 安装环境:CentOS-6.3 安装方式:源码安装  软件:apache-tomcat-7.0.29.tar.gz下载地址http://activemq.apache.org/downloa ...

  6. soa服务治理-dubbo

    dubbo官网:http://dubbo.io/Home-zh.htm 学习点: 1.  日志的配置

  7. C#笔记(二)变量

    C#把数据类型分为两种 ● 值类型 ● 引用类型 从概念上看:其区别是值类型直接存储其值,而引用类型存储对值的引用 这两种类型存储在内存的不同地方:值类型存储在堆栈中,而引用类型存储在托管堆上 如果变 ...

  8. jQuery中操作Ajax方法小结

    有时候,越深入去了解一个点,越发觉得自己无知,而之前当自己晓得一两个片面的点还洋洋自得,殊不知,这是多么讽刺 jQery对Ajax操作进行了封装,常见的 ajax()属于最底层的方法,使用频率很高的 ...

  9. Git之”make sure you have the correct access…”

    git 命令在windows下无法使用pull.fetch.push等命令,提示 “please make sure you have the correct access and the repos ...

  10. Abstraction elimination

    (本文不保证不误人子弟,切勿轻信) Unlambda指的是lambda计算中去掉lambda操作(does not have lambda(or abstraction) operation of t ...