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. 将root 当成arraylist放入数据sturts2 入门笔记

    刚启动idea 就报出错误 [-- ::,] Artifact -sturts2:war exploded: Error during artifact deployment. See server ...

  2. DAY24、面向对象

    一.复习继承1.父类:在类后()中写父类们2.属性查找顺序:自己->()左侧的父类->依次往右类推3.抽离:先定义子类,由子类的共性抽离出父类 派生:父类已经创建,通过父类再去派生子类4. ...

  3. idea安装成功后,设置字体、快捷键、配置jdk等操作

    设置字体 配置jdk 快捷键 复制当前一行: 设置自动提示,不区分大小写 关闭当前窗口 设置类头注释 自定义注释+注释快捷键 Lombok 插件安装  get.set方法报红cannot resolv ...

  4. tensorflow-TensorBoard

    Tensorborad--> 是Tensorflow的可视化工具,它可以通过Tensorflow程序运行过程中输出的日志文件可视化Tensorflow程序的运行状态.Tensorflow和Ten ...

  5. 洛谷P3469[POI2008]BLO-Blockade

    题目 割点模板题. 可以将图中的所有点分成两部分,一部分是去掉之后不影响图的连通性的点,一部分是去掉之后影响连通性的点,称其为割点. 然后分两种情况讨论,如果该点不是割点,则最终结果直接加上2*(n- ...

  6. 【转载】Nginx + Tomcat 实现反向代理

    通常的代理服务器,只用于代理内部网络对Internet的连接请求,客户机必须指定代理服务器,并将本来要直接发送到Web服务器上的http请求发送到代理服务器中由代理服务器向Internet上的web服 ...

  7. 贝叶斯推断 && 概率编程初探

    1. 写在之前的话 0x1:贝叶斯推断的思想 我们从一个例子开始我们本文的讨论.小明是一个编程老手,但是依然坚信bug仍有可能在代码中存在.于是,在实现了一段特别难的算法之后,他开始决定先来一个简单的 ...

  8. 在线批量修改mysql中表结构

    在线批量修改mysql中表结构 1.获取要修改的表的表名称登录mysql库,查询出所有表 show tables; 将需要修改表结构的表名称存放到b.txt文件中2.执行修改修改表引擎为InnoDB ...

  9. GIT-Linux(CentOS7)系统部署git服务器

    GIT-Linux(CentOS7)系统部署git服务器 root账号登录 一. 安装并配置必要的依赖关系在CentOS系统上安装所需的依赖:ssh,防火墙,postfix(用于邮件通知) ,wget ...

  10. [源码分析]读写锁ReentrantReadWriteLock

    一.简介 读写锁. 读锁之间是共享的. 写锁是独占的. 首先声明一点: 我在分析源码的时候, 把jdk源码复制出来进行中文的注释, 有时还进行编译调试什么的, 为了避免和jdk原生的类混淆, 我在类前 ...