迪杰斯特拉最短路径。

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. Mvc分页组件MvcSimplePager代码重构

    1 Mvc分页组件MvcSimplePager代码重构 1.1 Intro 1.2 MvcSimplePager 代码优化 1.3 MvcSimplePager 使用 1.4 End Mvc分页组件M ...

  2. oc之封装与类之间的关系

    1. 面向对象的特征-封装? 封装: 现实生活中的封装: 将很多的小东西 塞在1个大口袋里面. 好处: a. 对外部屏蔽. b. 方便管理. 代码的封装: 函数/方法 就是1种封装的体现: 将一段代码 ...

  3. django form表单验证

    一. django form表单验证引入 有时时候我们需要使用get,post,put等方式在前台HTML页面提交一些数据到后台处理例 ; <!DOCTYPE html> <html ...

  4. ionic2环境搭建与hello word

    一.环境搭建 需要安装配置以下组件,具体参考:Cordova环境搭建, 我的版本信息如下: 这里要特别注意,node版本,ionic2需要 大于v6 ,而不是0.xx版本,否则会不支持报错. 二.设置 ...

  5. React入门实例

    前言 React 的核心思想是:封装组件,各个组件维护自己的状态和UI,当状态变更,自动重新渲染整个组件. 理解:react首先值得拍手称赞的是它所有的开发都基于一个组件(component),组件和 ...

  6. [jQuery]on和bind事件绑定的区别

    on和bind事件绑定的区别 一个demo展示 <!DOCTYPE html> <html lang="zh"> <head> <titl ...

  7. c#-委托,匿名方法,lambda表达的关系

    什么是委托: 包含单个方法的委托和函数指针是相似的,不同的是,委托是面向帝乡的并且是类型安全的 声明委托类型: delegate void mydel(int x); 声明委托和声明方法差不多,两个不 ...

  8. ELK采集之nginx 之高德地图出城市IP分布图

    1.采用拓扑: 角色扮演: Agent:采用logstash,IP:192.168.10.7 Redis队列: IP:192.168.10.100 Indexer:logstash,IP:192.16 ...

  9. 【Spring】基于注解的实现SpringMVC+MySQL

    目录结构: // contents structure [-] SprinigMVC是什么 SpringMVC工作原理 @Controller和@RequestMapping注解 @Controlle ...

  10. 个人PE流程备忘

    insmod memdisk     linux16 /boot/memdisk iso raw   initrd16 /iso/Win8PE.iso