B - Frogger(floyd)C - Heavy Transportation(dijstra)

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
题意:求找从起点到终点需要的最短跳跃距离
那就要在这条路径中选出最大

#include 
#include 
//#include 
#include 
#include 
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
float map[202][202];
int n,m;
float mi;
float max(float a,float b)
{
    if(a>b) return a;
    else return b;
}
void floyd() //也可以用dijstra
{
    int i,k,j;mi=INF;
    for(k=0;kmax(map[i][k],map[k][j]))//到达某一点路径中最大值的更换成较小的
                {
                    map[i][j]=map[j][i]=max(map[i][k],map[k][j]);
                }
            }
        }
    }
}
struct node
{
    int x,y;
}p[202];
float dis(node a,node b)
{
    float z;
    z=sqrt(float(a.x-b.x)*(a.x-b.x)+float(a.y-b.y)*(a.y-b.y));//强制转换类型
    return z;
}
int main()
{
    int i,j,cnt=0;
    float w;
    while(scanf("%d",&n)!=EOF&&n)
    {
        cnt++;
        for(i=0;iw)
                map[i][j]=map[j][i]=w;
            }
        }
        floyd();
        printf("Scenario #%d\n",cnt);
        printf("Frog Distance = %.3f\n\n",map[0][1]);
    }
    return 0;
}

C - Heavy Transportation
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

#include 
#include 
#include 
#include 
#include 
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int map[1001][1001];
int n,m;
void dijstra(int t)
{
    int i,j,mi;
    int vis[1001],dis[1001];
    memset(vis,0,sizeof(vis));
    memset(dis,0,sizeof(dis));
    for(i=1; i<=n; i++)
    {
        dis[i]=map[t][i];
    }
    vis[t]=1;
    for(i=1; iminn&&!vis[j]) //直接找大的
            {
                minn=dis[j];
                mi=j;
            }
        }
        vis[mi]=1;
        for(j=1; j<=n; j++)
        {
            if(!vis[j]&&dis[j]

你可能感兴趣的:(最短路)