UVa 544 - Heavy Cargo
来源:互联网 发布:密立根油滴学生数据 编辑:程序博客网 时间:2024/05/17 03:06
题目:有一个载重无限的卡车运输货物,在城市中每条道路有一个能承受的最大重量,
现在用卡车从一个城市到另一个城市运送货物,问最大的运输重量。
分析:图论,最短路,最小生成树。找一条从起点到终点的路径,使得其中最窄的路段最宽。
从起点开始不断向周围扩散,像dijkstra算法和prime算法一样,只是维护最大值即可。
(如果上述方法不正确,则存在在一个确定点,其后面的确定点可以更新它,则在那个点应该先被找到)
说明:道路是双向的,重复的路径认为是扩建,加和处理。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;/*hash_satrt*/typedef struct hash_node{int id;char name[31];hash_node*next;}hash_node;hash_node Node[202];hash_node* List[10007];int list_size = 0;void hash_initial(){list_size = 0;memset(List, 0, sizeof(List));memset(Node, 0, sizeof(Node));}int hash_hash(char *word){int value = 0;for (int i = 0 ; word[i] ; ++ i)value = value * word[i] % 10007;return value;}int hash_find(char *word){int value = hash_hash(word);for (hash_node *p = List[value] ; p ; p = p->next)if (!strcmp(p->name, word))return p->id;Node[list_size].id = list_size;strcpy(Node[list_size].name, word);Node[list_size].next = List[value];List[value] = &Node[list_size ++];return list_size-1;}/*hash_end*/int maps[101][101];int path[101],used[101];char buf1[31],buf2[31];int deal(int s, int t, int n){for (int i = 0 ; i < n ; ++ i) path[i] = used[i] = 0;path[s] = 10001;used[s] = 1;for (int i = 1 ; i < n ; ++ i) {for (int j = 0 ; j < n ; ++ j)if (!used[j] && maps[s][j])path[j] = max(path[j], min(maps[s][j], path[s]));int Max = 0;for (int j = 0 ; j < n ; ++ j) if (!used[j] && Max < path[j]) {s = j;Max = path[j];}used[s] = 1;}return path[t];}int main(){int m,n,p,a,b,Case = 1;while (~scanf("%d%d",&n,&m) && n) {hash_initial();memset(maps, 0, sizeof(maps));for (int i = 0 ; i < m ; ++ i) {scanf("%s%s%d",buf1,buf2,&p);a = hash_find(buf1);b = hash_find(buf2);maps[a][b] += p;maps[b][a] += p;}scanf("%s%s",buf1,buf2);printf("Scenario #%d\n",Case ++);printf("%d tons\n\n",deal(hash_find(buf1), hash_find(buf2), n));} return 0;}
0 0
- UVa 544 - Heavy Cargo
- uva 544 - Heavy Cargo(生成树)
- 544 - Heavy Cargo
- UVa 544 Heavy Cargo( 最小生成树的variant)
- (beginer) 最小生成树 UVA 544 Heavy Cargo
- UVA 544 - Heavy Cargo(最小瓶颈路)
- ZJU 1952 Heavy Cargo
- zoj 1952 Heavy Cargo
- POJ 2263 Heavy Cargo
- poj 2263 Heavy Cargo
- zoj 1952 Heavy Cargo
- POJ2263:Heavy Cargo
- poj_2263 Heavy Cargo (Dijkstra)
- poj 2263 Heavy Cargo
- 12:Heavy Cargo
- zoj Heavy Cargo
- POJ 2263 Heavy Cargo
- poj 2263 Heavy Cargo
- VS2013编译libjpeg库
- OpenCV基础03(图像变换+)
- Java处理txt文件遇到的问题 (unicode编码)
- 进程间通信 华清远见-《嵌入式 Linux 应用程序开发标准教程》学习记录
- GIS项目与GIS二次开发
- UVa 544 - Heavy Cargo
- 创业者的2014:最痛苦的是人和方向
- 国内眼动仪选购调研
- opencv7-ml之svm(3)应用
- init.d脚本和openwrt程序自启动
- oracle在groupby时间时,时间间断问题处理
- Java多线程的synchronized和Lock
- 矩阵相乘!
- 比较java新旧I/O的性能——以复制大文件为例