zoj 1655 Transport Goods Dijkstra
来源:互联网 发布:给死人烧纸有用吗 知乎 编辑:程序博客网 时间:2024/05/02 11:49
Description
The HERO country is attacked by other country. The intruder is attacking the capital so other cities must send supports to the capital. There are some roads between the cities and the goods must be transported along the roads.
According the length of a road and the weight of the goods, there will be some cost during transporting. The cost rate of each road is the ratio of the cost to the weight of the goods transporting on the road. It is guaranteed that the cost rate is less than 1.
On the other hand, every city must wait till all the goods arrive, and then transport the arriving goods together with its own goods to the next city. One city can only transport the goods to one city.
Your task is find the maximum weight of goods which can arrive at the capital.
Input
There are several cases.
For each case, there are two integers N (2 <= N <= 100) and M in the first line, where N is the number of cities including the capital (the capital is marked by N, and the other cities are marked from 1 to N-1), and M is the number of roads.
Then N-1 lines follow. The i-th (1 <= i <= N - 1) line contains a positive integer (<= 5000) which represents the weight of goods which the i-th city will transport to the capital.
The following M lines represent M roads. There are three numbers A, B, and C in each line which represent that there is a road between city A and city B, and the cost rate of this road is C.
Process to the end of the file.
Output
For each case, output in one line the maximum weight which can be transported to the capital, accurate up to 2 demical places.
Sample Input
5 6
10
10
10
10
1 3 0
1 4 0
2 3 0
2 4 0
3 5 0
4 5 0
Sample Output
40.00
题意及分析:
是一道比较有意思的最短路问题。关键在于把最短路的模型抽象出来。
从编号为1~n-1的点运输物品到编号为n的点。当上一个城市的物品到达下一个城市后,下一个城市的物品要和与它一起运输。运输过程每条路都会有一定的损耗,为运输物品的总质量乘以每条路相应的比例。现在要使最后运到n的物品重量最大。
题目的描述有一定的迷惑性。其实一起运和单独运,损耗计算是一样的。发现了这点。那么思路就渐渐清晰了。所以,只要任一城市出发的物品到n的损耗最小,总的损耗就最少。另外要想到的一点就是,同样重量的物品,从i到n,和,从n到i 损耗率其实是一样的。到了现在,只要求出了从n出发到各点的最小的损耗率,那么问题就解决了。
AC代码:
- ZOJ--1655--Transport Goods【dijkstra】
- zoj 1655 Transport Goods Dijkstra
- zoj 1655 Transport Goods(dijkstra)
- zoj 1655 Transport Goods(Dijkstra~~)
- ZOJ 1655 Transport Goods 【最短路】【Dijkstra】
- ZOJ 1655 Transport Goods(dijkstra最短路)
- TOJ 3018 ZOJ 1655 Transport Goods / dijkstra
- ZOJ 1655 Transport Goods
- ZOJ 1655 Transport Goods
- ZOJ-1655-Transport Goods
- ZOJ 1655 Transport Goods
- ZOJ 1655 Transport Goods
- ZOJ 1655 Transport Goods
- ZOJ 1655 Transport Goods
- ZOJ-1655 Transport Goods
- zoj 1655 Transport Goods
- ZOJ 1655 Transport Goods (杀入ranklist1000,撒花)
- ZOJ 1655 Transport Goods 最短路变形
- dedecms添加自定义属性
- ActiveReport入门教程(二) - 单选按钮
- poj 1654 Area
- POJ 1487 Single-Player Games
- O符号的简明解释
- zoj 1655 Transport Goods Dijkstra
- 在Android中查看和管理sqlite数据库
- Android所有控件
- Device-Mapper+Multipath
- Servlet页面间对象传递的方法
- android从一个类跳转到另一个类的基本操作
- 你是我第一个成功,第二个是事业。
- 注解
- Swift初窥----深入Swift