http://poj.org/problem?id=2263

题意:汽车的载重量没有限制,取决于道路的承载能力,求起点到终点所经过的路径不会超过道路的承载限制。

分析:本题并不是求最短路径,而是求通过的能力最大的路,这种路可以称作最大容量路,可以用floyd算法的思想求解。设城市i到城市j的承载能力记为【i,j】,初始时K到M没有直接路径,因此k到M的承载重量为0。即【K,M】=0.加入中间结点H后,K到M的承载重量改为MAX{【K,M】,MIN([K,H],[H,K])};

View Code

  1 // I'm the Topcoder
  2 //C
  3 #include <stdio.h>
  4 #include <stdlib.h>
  5 #include <string.h>
  6 #include <ctype.h>
  7 #include <math.h>
  8 #include <time.h>
  9 //C++
 10 #include <iostream>
 11 #include <algorithm>
 12 #include <cstdio>
 13 #include <cstdlib>
 14 #include <cmath>
 15 #include <cstring>
 16 #include <cctype>
 17 #include <stack>
 18 #include <string>
 19 #include <list>
 20 #include <queue>
 21 #include <map>
 22 #include <vector>
 23 #include <deque>
 24 #include <set>
 25 using namespace std;
 26
 27 //*************************OUTPUT*************************
 28 #ifdef WIN32
 29 #define INT64 "%I64d"
 30 #define UINT64 "%I64u"
 31 #else
 32 #define INT64 "%lld"
 33 #define UINT64 "%llu"
 34 #endif
 35
 36 //**************************CONSTANT***********************
 37 #define INF 0x3f3f3f3f
 38 #define eps 1e-8
 39 #define PI acos(-1.)
 40 #define PI2 asin (1.);
 41 typedef long long LL;
 42 //typedef __int64 LL;   //codeforces
 43 typedef unsigned int ui;
 44 typedef unsigned long long ui64;
 45 #define MP make_pair
 46 typedef vector<int> VI;
 47 typedef pair<int, int> PII;
 48 #define pb push_back
 49 #define mp make_pair
 50
 51 //***************************SENTENCE************************
 52 #define CL(a,b) memset (a, b, sizeof (a))
 53 #define sqr(a,b) sqrt ((double)(a)*(a) + (double)(b)*(b))
 54 #define sqr3(a,b,c) sqrt((double)(a)*(a) + (double)(b)*(b) + (double)(c)*(c))
 55
 56 //****************************FUNCTION************************
 57 template <typename T> double DIS(T va, T vb) { return sqr(va.x - vb.x, va.y - vb.y); }
 58 template <class T> inline T INTEGER_LEN(T v) { int len = 1; while (v /= 10) ++len; return len; }
 59 template <typename T> inline T square(T va, T vb) { return va * va + vb * vb; }
 60
 61 // aply for the memory of the stack
 62 //#pragma comment (linker, "/STACK:1024000000,1024000000")
 63 //end
 64
 65 #define maxcities 256+10
 66 int kase=0;//测试数据序号
 67 int n,r;
 68 int w[maxcities][maxcities];//floyd算法中A矩阵
 69 char city[maxcities][30+10];//城市名
 70 char start[30+10],dest[30+10];
 71
 72 int numcities;//城市名在city数组中的序号
 73
 74
 75 //把陆陆续续进来的城市名存储到city数组中,index函数的功能是给定一个城市名
 76 //返回它在city数组中的下标,if不存在,则把该城市名追加到city数组中
 77 int index(char* s){
 78     int i;
 79     for(i=0;i<numcities;i++){
 80         if(!strcmp(city[i],s))  return i;
 81     }
 82     strcpy(city[i],s);
 83     numcities++;
 84     return i;
 85 }
 86
 87
 88 //读入测试数据
 89 int read_case(){
 90     int limit;
 91     scanf("%d%d",&n,&r);
 92     if(n==0 ) return 0;
 93     //初始化数组
 94     for(int i=0;i<n;i++){
 95         for(int j=0;j<n;j++){
 96             w[i][j]=0;
 97         }
 98     }
 99     for(int i=0;i<n;i++)  w[i][i]=INF;
100     //读入道路网络
101     numcities=0;
102     for(int k=0;k<r;k++){
103         scanf("%s%s%d",start,dest,&limit);
104         int i=index(start);
105         int j=index(dest);
106         w[i][j]=w[j][i]=limit;//floyd算法中矩阵A的初始值就是邻接矩阵
107     }
108     //读入起始城市和终点城市
109     scanf("%s%s",start,dest);
110     return 1;
111 }
112
113 void floyd(){
114     for(int k=0;k<n;k++){
115         for(int i=0;i<n;i++){
116             for(int j=0;j<n;j++){
117                 w[i][j]=max(w[i][j],min(w[i][k],w[k][j]));
118             }
119         }
120     }
121 }
122
123 void solve_case(){
124     //floyd()
125     floyd();
126     int i=index(start);
127     int j=index(dest);
128     printf("Scenario #%d\n",++kase);
129     printf("%d tons\n\n",w[i][j]);
130 }
131
132 int main(){
133     while(read_case()){
134         solve_case();
135     }
136     return 0;
137 }

转载于:https://www.cnblogs.com/lanjiangzhou/archive/2013/03/24/2979809.html

POJ 2263 floyd思想相关推荐

  1. POJ - 3613 Cow Relays(Floyd思想+矩阵快速幂+动态规划)

    题目链接:点击查看 题目大意:给定一张由T(T<=100)条边构成的无向图,点的编号为1~1000,之间的整数,求从起点S到终点E恰好经过N(N<=1e6)条边(可重复经过)的最短路 题目 ...

  2. Poj(2240),Floyd求汇率是不是赚钱

    题目链接:http://poj.org/problem?id=2240. Floyd算法修改一下,我要最大路径(通过转汇率变到最大)改成max. #include <iostream> # ...

  3. POJ 3615 floyd 求任意起点终点的最短路

    http://poj.org/problem?id=3615 题意:求起点到终点的最短路,不存在则输出-1.这题居然tle两次,把floyd放在外面就行了. View Code // I'm lanj ...

  4. Dijkstra解决POJ 2263

    题目:http://poj.org/problem?id=2263 题目大意:有n个城市,r条连接两个城市的道路,每条道路有自己的最大复载量.现在问从城市cst到城市cen,车上的最大载重能为多少. ...

  5. The Geodetic Set Problem - POJ 1612 Floyd求最短路径所有点集

    题目链接 POJ 1612 Description Let G = (V,E) be a connected graph without loops and multiple edges, where ...

  6. Cow Contest POJ - 3660 Floyd算法,关系链图

    N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...

  7. 【A - TT 的魔法猫】Floyd思想

    题意: 有一张游戏胜负表,上面有 N 个人以及 M 个胜负关系,每个胜负关系为 A B,表示 A 能胜过 B,且胜负关系具有传递性.即 A 胜过 B,B 胜过 C,则 A 也能胜过 C.求有多少对选手 ...

  8. poj 3660(Floyd求传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9317   Accepted: 5249 Descr ...

  9. poj 3660(floyd 变形)

    题意: 有N头牛,每头牛都会有比他强的或者弱的牛,按照牛的强弱排序,问有几头牛的位置是确定的. 5 5(n,m) 4 3 4 2 3 2 1 2 2 5则4>3>2>5 && ...

最新文章

  1. javascript基础语法——表达式
  2. 网络加速和优化控制常用管理
  3. mysql slave lock 跳过_slave开启MTS时执行mysqldump引发死锁案例
  4. VSCode 初次写vue项目并一键生成.vue模版
  5. HDbaseT 高清传输更简单——只需一根网线
  6. long long or int
  7. MiniDao支持ID自增主键策略,使用讲解
  8. SAP License:ERP概述
  9. 【机器学习】Andrew Ng——04多变量线性回归
  10. 48V自动启停的Stateflow应用
  11. MSDN for VC 6.0 MSDN下载地址
  12. db9串口(db9串口定义及颜色)
  13. 光伏发电与计算机控制,独立太阳能光伏发电系统的控制设计与实现
  14. 华为p9总显示切换服务器中,怎么更改华为p9的多任务切换 | 手游网游页游攻略大全...
  15. 学习使用php的stripslashe()函数去除反斜杠
  16. 淘宝上卖云控系统靠谱吗?
  17. 两台windows电脑通过以太网互ping
  18. SVPWM的一些理解
  19. 【数理统计】双因素方差分析
  20. matplotlib animation 模拟弹簧的强迫振动 以及odeint函数的应用

热门文章

  1. cad输入法自动切换_百度输入法 Linux 版本发布,支持 Ubuntu/Deepin
  2. 地址总线是单向还是双向_三端双向交流开关(TRIAC)
  3. C语言ODBC方式连接DM数据库
  4. 【读书笔记】沉默的大多数
  5. TCP/IP学习笔记(七)四次挥手
  6. 每天一道LeetCode-----为二叉树增加next节点,指向同一层的下一个节点
  7. 每天一道LeetCode-----数独盘求解
  8. add_compile_options和CMAKE_CXX_FLAGS的区别
  9. 贝叶斯告诉你,投掷硬币概率可以是90%
  10. HDU 2050 折线分割平面