Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.

Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.

Problem

You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.

Input

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.

Sample Input

1
3 3
1 2 3
1 3 4
2 3 5

Sample Output

Scenario #1:
4
思路:
这一道题就是说假如从a到b的路有好几条,在每条路上都要过几个路口,路口与路口之间的有一个标量的意思就是过这条路的最大质量是多少。。那就是说
求出来这一条路上面的最小值,只有小于等于这个值的货物才能通过这条路到达终点。。
但是要注意从a到b的路有可能不止一条,所以我们就要去求所有能到达终点每条路的最小值,再在最小值中取最大值
解决这道题的方法:选择迪杰斯方法的变形,具体实现就是给那个记录单源最短路长度的数组全部赋值为0,再把起点的距离设为无穷大,放入优先队列中
在每一次的判断d[终点]<min(d[起点],从起点到终点边的距离)
还要注意的是在使用优先队列的优先也发生了变化,我们是求每一条路上边的最小值,最后在所有的情况中取最大值
所以说我们要求的是最大值,这就和最短路不一样了,因此我们要改变优先级
代码如下:
 //终于A了。。。
//原来这一道题优先队列的优先也和最短路的不一样,因为这是要求出来每一条路的最小边,
//在在众多边进行对比找出来那个最大的。那么在刚开始对与七点相连的边进行一次遍历之后
//就要找出来d中最大的值,再从他开始遍历。。。。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int MAX=;
const int INF=0xffffff;
int n,m,d[MAX],dis[MAX];
struct shudui1
{
int start,value;
bool operator <(const shudui1 q)const
{
return value<q.value;
}
}str1;
struct shudui2
{
int start,value;
}str2;
priority_queue<shudui1>r;
vector<shudui2>w[MAX];
void JK()
{
memset(dis,,sizeof(dis));
while(!r.empty())
{
str1=r.top();
r.pop();
int x=str1.start;
if(dis[x]) continue;
dis[x]=;
int len=w[x].size();
for(int i=;i<len;++i)
{
str2=w[x][i];
if(!dis[str2.start] && d[str2.start]<min(d[x],str2.value))
{
str1.value=d[str2.start]=min(d[x],str2.value);
str1.start=str2.start;
r.push(str1);
}
}
}
}
int main()
{
int t,k=;
scanf("%d",&t);
while(t--)
{
k++;
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i)
{
w[i].clear();
}
memset(d,,sizeof(d));
while(m--)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
str2.start=y;
str2.value=z;
w[x].push_back(str2);
str2.start=x;
w[y].push_back(str2);
}
d[]=INF;
str1.start=;
str1.value=INF;
r.push(str1);
JK(); printf("Scenario #%d:\n",k);
printf("%d\n\n",d[n]);
}
return ;
}
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her by jumping.
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.

To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.

The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.

You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.

Input

The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy's stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.

Output

For each test case, print a line saying "Scenario #x" and a line saying "Frog Distance = y" where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last one.

Sample Input

2
0 0
3 4 3
17 4
19 4
18 5 0

Sample Output

Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414
这一道题与上面那一道题刚好相反
这一道题就是求出来从起点到终点的每一条路上面的边的最大值,和上一个差不多,这个也有好几条路,但是这个要在所有路中求最小值(花里胡哨)
这个对前期数组处理要把数组初始化为无穷大,那个起点是初始化为0
其他按照正常最短路就可以过
代码如下:
 //这一道题难受死我了,这个问题我也是醉了。。。
//题意:
//青蛙一是第一个输入的数据
//青蛙而是第二个
//由于从青蛙一到青蛙二的路有好几条,青蛙一也可以直接蹦到青蛙二的位置
//所以要求这几条路中他们各自的蹦跳的最大值
//在在这几条路中的最大值中求最小值。。。。。<_>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct shudui1
{
int start;
double value;
bool operator < (const shudui1 e)const
{
return value>e.value;
}
}str1;
struct shudui2
{
int start;
double value;
}str2;
struct shudui3
{
double x,y;
}m[];
vector<shudui2>w[];
priority_queue<shudui1>r;
const double INF=0xffffff;
double v[];
int dis[];
int a,s,d,k=;
void JK()
{
//vis[1]=0;
while(!r.empty())
{
str1=r.top();
r.pop();
int x=str1.start;
double y=str1.value;
// if(v[x]<y)
// {
// // printf("****\n");
// continue;
// }
if(dis[x]) continue;
dis[x]=;
int len=w[x].size();
//printf("%d %d \n",len,str1.start);
for(int i=;i<len;++i)
{
str2=w[x][i];
// printf("%d %d %d %d\n",v[str2.start],v[x],str2.value,str2.start);
if(v[str2.start]>max(v[x],str2.value)) // 做题方法大致不变,但是v中存的值要改变,假比
// v[2]中原来值为2-------是青蛙一直接蹦了过去
// 但是从青蛙一蹦到三号点距离为1.414,再从三号点蹦到二号点2--3--->距离:1.414
// 此时大都青蛙二的路有两条
// 1--->2;
// 1--->3---->2,三中存的是一到三的最大值,到二的时候比较的时侯,v[3]就代表之前所有者一条路上的最大边,
// 此时他的value是三道二这条边的长度,这样就相当于二中存的是1到2这条路上的边的最大值
// 之后赋值给二的时候,如果二中有值,就代表这是其他路到二位值的最大值,再次赋值时要比较
{
// printf("******\n");
v[str2.start]=max(v[x],str2.value);
//v[str2.start]=v[x]+str2.value;
str1.start=str2.start;
str1.value=v[str2.start];
r.push(str1);
}
}
}
}
int main()
{
while(~scanf("%d",&a))
{
k++;
if(a==) break;
memset(dis,,sizeof(dis));
//memset(vis,0x3f,sizeof(vis));
// for(int i=1;i<=a;++i)
// {
// vis[i]=INF;
// }
for(int i=;i<=a;++i)
v[i]=INF;
for(int i=;i<=a;++i)
{
scanf("%lf%lf",&m[i].x,&m[i].y);
}
double q;
for(int i=;i<a;++i)
{
for(int j=i+;j<=a;++j)
{
//if((i==1 && j==2) || (i==2 && j==1)) continue;
//if(i==j) continue;
q=sqrt((m[i].x-m[j].x)*(m[i].x-m[j].x)+(m[i].y-m[j].y)*(m[i].y-m[j].y));
str2.start=j;
str2.value=q;
w[i].push_back(str2);
str2.start=i;
w[j].push_back(str2);
//printf("%d %d %lf\n",i,j,q);
}
}
// printf("%d %d\n",w[1][0].start,w[1].size());
v[]=;
str1.start=;
str1.value=;
r.push(str1);
JK();
printf("Scenario #%d\n",k);
printf("Frog Distance = %.3lf\n",v[]);
//r.clear();
for(int i=;i<=a;++i)
w[i].clear();
printf("\n");
}
return ;
}


C - Heavy Transportation && B - Frogger(迪杰斯变形)的更多相关文章

  1. Heavy Transportation POJ 1797 最短路变形

    Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...

  2. poj1797 - Heavy Transportation(最大边,最短路变形spfa)

    题目大意: 给你以T, 代表T组测试数据,一个n代表有n个点, 一个m代表有m条边, 每条边有三个参数,a,b,c表示从a到b的这条路上最大的承受重量是c, 让你找出一条线路,要求出在这条线路上的最小 ...

  3. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  4. POJ1797 Heavy Transportation —— 最短路变形

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  5. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  6. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  7. POJ 1797 Heavy Transportation SPFA变形

    原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  8. poj 1797 Heavy Transportation(最短路径Dijkdtra)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 26968   Accepted: ...

  9. Heavy Transportation(最短路 + dp)

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. git bash 连接github并提交项目工程

    借鉴博客:https://www.cnblogs.com/flora5/p/7152556.html https://blog.csdn.net/heng_yan/article/details/79 ...

  2. MT 互联网 面试标准

    能力模型 业务理解(每项2分) java知识(每项2分) 网络知识(每项1分) 设计模式(每项3分) 数据库知识(每项2分) 框架知识(每项1分) 数据结构与算法(每项1分) 架构知识(每项3分) 操 ...

  3. k8s-jenkins 自动化1

    一个流水线例子: 设置参数化构建: 流水线指令: def label = "docker-${UUID.randomUUID().toString()}" podTemplate( ...

  4. vue router 修改title(IOS 下动态改变title失效)

    在ios下app  设置document.title = "titleName" 失效,原因是在IOS webview中网页标题只加载一次,动态改变是无效的. 在路由配置中添加   ...

  5. MSSQL-最佳实践-Always Encrypted

    摘要 在SQL Server安全系列专题月报分享中,往期我们已经陆续分享了:如何使用对称密钥实现SQL Server列加密技术.使用非对称密钥实现SQL Server列加密.使用混合密钥实现SQL S ...

  6. CCF201812-3 CIDR合并

    按题意模拟即可...主要CCF吞代码... #include<bits/stdc++.h> #define pb push_back #define mp make_pair #defin ...

  7. 修改linux下yum镜像源为国内镜像

    修改为163yum源-mirrors.163.com 1.首先备份系统自带yum源配置文件/etc/yum.repos.d/CentOS-Base.repo [root@localhost ~]# m ...

  8. 【linux】常用命令集锦&持续更新...

    滴:转载引用请注明哦[握爪]:https://www.cnblogs.com/zyrb/p/9709013.html  对深度学习训练及日常work中的常用linux命令进行整理. [一]screen ...

  9. 对于Sobel算子的学习

    本来想说很多目前对于 Sobel 算子的认识,但最终还是觉得对于其掌握程度太低,没有一个系统的理解,远不足以写博客,但为了12月不至于零输出,还是决定把自己学习过程中找到的相关资料进行分享. 等到一月 ...

  10. c++对象的存储空间

    1. 非静态成员 2. 静态成员变量 静态成员变量不占对象的内存空间 3. 成员函数 成员函数不占内存空间 4. 析构函数 5. 类中有虚析构函数 6. 继承空类和多重继承空类存储空间的计算 7. t ...