ZOJ 1655 FZU 1125 Transport Goods
迪杰斯特拉最短路径。
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的更多相关文章
- ZOJ - 1655 Transport Goods(单源最长路+迪杰斯特拉算法)
题目: 有N-1个城市给首都(第N个城市)支援物资,有M条路,走每条路要耗费一定百分比(相对于这条路的起点的物资)的物资.问给定N-1个城市将要提供的物资,和每条路的消耗百分比.求能送到首都的最多的物 ...
- ZOJ1655 Transport Goods(Floyd)
利用Floyd的DP状态转移方程. #include<cstdio> #include<cstring> #include<queue> #include<a ...
- zoj 1655 单源最短路 改为比例+最长路
http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=655 没有理解清题意就硬套模板.所以WA了好几次. 解析看我的还有一篇http ...
- Goods transportation
Goods transportation time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 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 ...
- [codeforces724E]Goods transportation
[codeforces724E]Goods transportation 试题描述 There are n cities located along the one-way road. Cities ...
- Minimum Cost(最小费用最大流)
Description Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his s ...
- POJ 2516 Minimum Cost (费用流)
题面 Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area ...
- POJ 2516 Minimum Cost (网络流,最小费用流)
POJ 2516 Minimum Cost (网络流,最小费用流) Description Dearboy, a goods victualer, now comes to a big problem ...
随机推荐
- Javascript使用postMessage对iframe跨域通信
今天才发现原来有这么个好东西啊,跨域通信太方便了, 举个小栗子: 共两个页面, 页面1:www.a.com/a.html 页面2:www.b.com/b.html 实现目标:两个网站页面实现跨域相互通 ...
- BHuman文档结构
Chapter 2 : a short introduction how to build the code including the required software and how to ru ...
- linux-命令-top
top 实时动态显示系统状态.(cpu.内存.swap.task) 1. top 汇总cpu.内存.swap.task信息 和 列表展示进程维度的cpu.内存.swap.task信息 2. to ...
- Girl Develop It Chapter Leaders at 2015 Annual Leadership Summit
Girl Develop It Chapter Leaders at 2015 Annual Leadership Summit Corinne Warnshuis, Executive Direct ...
- 终于了解了User-Agent的历史了
你是否好奇标识浏览器身份的User-Agent,为什么每个浏览器都有Mozilla字样? 1 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.3 ...
- mysql vachar
--本文在CSDN文章的基础加以补充 一. varchar存储规则: 4.0版本以下,varchar(20),指的是20字节,如果存放UTF8汉字时,只能存6个(每个汉字3字节) 5.0版本以上,va ...
- Chapter 21_5.2 tab扩展
在Lua中,像这样()的空白捕获具有特殊意义.表示捕获它在目标字符串中的位置,返回一个数字: print(string.match("hello","()ll()&quo ...
- iOS杂货
iOS 导航栏TitleView居中的问题 titleVIew 默认情况下 是居中显示的,出现不居中的情况原因有两个:1,leftBarButtonItem,和rightBarButtonItem 留 ...
- Android如何查看应用签名信息
转自http://www.trinea.cn/android/android-view-signatures/comment-page-1/ 介绍Android如何查看自己的应用签名及三方APK或系统 ...
- 一个在浏览器端将html 转为pdf 的js 插件 jsPDF
<!DOCTYPE html> <html> <head> <title>test</title> <meta http-equiv= ...