最短路变形 poj3615&
问题:
牛要跨过一些障碍,希望以最小的体力跨过障碍,并且对于一条路径,只在乎其中最高的障碍。
输入N代表站点数,标记为1—N,输入M代表路径数,从站点S到E之间需要跨过高度为H的障碍。
输入T代表牛要完成的任务数。对于每个任务,输入A,B,输出一条从站点A到B的路径,使需要跨过的最高障碍为最低。
代码:(Floyd
/*******************************************
Problem: 3615 User:
Memory: 960K Time: 688MS
Language: G++ Result: Accepted
********************************************/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 305; int mp[N][N];
int dis[N], vis[N]; void floyd(int n)
{
int i, j, k;
for (k = 1; k <= n; ++k)
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j)
if (mp[i][j] > max(mp[i][k] , mp[k][j]))
mp[i][j] = max(mp[i][k], mp[k][j]);
} int main()
{
int n, m, t;
while (scanf("%d%d%d", &n, &m, &t) != EOF) {
int i, j;
int a, b, h;
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j)
mp[i][j] = INF;
for (i = 0; i < m; ++i) {
scanf("%d%d%d", &a, &b, &h);
mp[a][b] = h;
}
floyd(n);
for (i = 0; i < t; ++i) {
scanf("%d%d", &a, &b);
printf("%d\n", mp[a][b] == INF ? -1 : mp[a][b]);
}
}
return 0;
}
poj2263
和上题相似,求两点之间最小值最大的路径
代码:(dijkstra
/******************************************
Problem: 2263 User:
Memory: 812K Time: 125MS
Language: G++ Result: Accepted
*******************************************/
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std; const int N = 205;
const int INF = 0x3f3f3f3f; int mp[N][N];
int vis[N], dis[N];
map<string, int>my_map; int dijkstra(int n, int s, int e)
{
int i, j;
memset(vis, 0, sizeof(vis));
for (i = 1; i <= n; ++i)
dis[i] = mp[s][i];
vis[s] = 1;
for (i = 0; i < n; ++i) {
int max_dis = 0;
int max_x = 1;
for (j = 1; j <= n; ++j) {
if (!vis[j] && dis[j] > max_dis) {
max_dis = dis[j];
max_x = j;
}
}
if (max_x == e) return max_dis;
vis[max_x] = 1;
for (j = 1; j <= n; ++j) {
if (!vis[j] && dis[j] < min(dis[max_x], mp[j][max_x]))
dis[j] = min(dis[max_x], mp[j][max_x]);
}
}
return 0;
} int main()
{
int n, m;
int times = 1;
while (scanf("%d%d", &n, &m) != EOF) {
if (n == 0 && m == 0) break;
int i, j;
my_map.clear();
int cnt = 1;
string stra, strb;
int x, y;
int weight;
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j)
mp[i][j] = 0; for (i = 0; i < m; ++i) {
cin >> stra >> strb >> weight;
if (my_map[stra] == 0) my_map[stra] = cnt++;
if (my_map[strb] == 0) my_map[strb] = cnt++;
x = my_map[stra];
y = my_map[strb];
if (mp[x][y] < weight)
mp[y][x] = mp[x][y] = weight;
}
cin >> stra >> strb;
x = my_map[stra];
y = my_map[strb];
printf("Scenario #%d\n%d tons\n\n", times++, dijkstra(n, x, y)); }
return 0;
}
最短路变形 poj3615&的更多相关文章
- 对短路变形POJ3615
Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are ...
- 最短路变形 poj3615& poj2263
问题: 牛要跨过一些障碍,希望以最小的体力跨过障碍,并且对于一条路径,只在乎其中最高的障碍. 输入N代表站点数,标记为1—N,输入M代表路径数,从站点S到E之间需要跨过高度为H的障碍. 输入T代表牛要 ...
- POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
- POJ 3635 - Full Tank? - [最短路变形][手写二叉堆优化Dijkstra][配对堆优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: ...
- POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 Description After going through the receipts from your car trip ...
- POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Description Background Hugo ...
- HDOJ find the safest road 1596【最短路变形】
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HN0I2000最优乘车 (最短路变形)
HN0I2000最优乘车 (最短路变形) 版权声明:本篇随笔版权归作者YJSheep(www.cnblogs.com/yangyaojia)所有,转载请保留原地址! [试题]为了简化城市公共汽车收费系 ...
- 天梯杯 PAT L2-001. 紧急救援 最短路变形
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上.当其他城市有紧急求 ...
随机推荐
- ColorDialog组件设置字体颜色
1.设置颜色 private void button4_Click(object sender, EventArgs e) { this.colorDialog1.ShowDialog(); this ...
- CODEVS 1132 瑞士轮
题目描述 Description 背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平, ...
- Nhibernate cookbook 3.0-翻译
/* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-ts ...
- iOS 页面间传值 之 属性传值,代理传值
手机 APP 运行,不同页面间传值是必不可少,传值的方式有很多(方法传值,属性传值,代理传值,单例传值) ,这里主要总结下属性传值和代理传值. 属性传值:属性传值是最简单,也是最常见的一种传值方式,但 ...
- CSS3制作下拉菜单
导航菜单其实是没有什么可说的,制作方法到处可见,今天这个案例本来不只是一个导 航,还有一个搜索表单的,可是为了偷懒,把搜索表单部分去掉了,就变成了一个CSS3 制作的下拉菜单.在这个导航中主要两点,一 ...
- java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=186646784)(ERR=12505)(ERR
dbc 链接orcal出错 java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=186646784)( ...
- MD5算法步骤详解
转自MD5算法步骤详解 之前要写一个MD5程序,但是从网络上看到的资料基本上一样,只是讲了一个大概.经过我自己的实践,我决定写一个心得,给需要实现MD5,但又不要求很高深的编程知识的童鞋参考.不多说了 ...
- Android中改变dialog的显示的位置和大小
private void setDialogSize(Dialog dg) { Window dialogWindow = dg.getWindow(); WindowManager.LayoutPa ...
- 对TCP/IP网络协议的深入浅出归纳(转)
前段时间做了一个开发,涉及到网络编程,开发过程比较顺利,但任务完成后始终觉得有一些疑惑.主要是因为对网络协议不太熟悉,对一些概念也没弄清楚.后来 我花了一些时间去了解这些网络协议,现在对TCP/IP网 ...
- WCF - Self Hosting
WCF - Self Hosting Here, the WCF service is hosted in a console application. Given below is the proc ...