zoukankan      html  css  js  c++  java
  • POJ 2253 Frogger

    Frogger

    Description

    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
    
    1为起点,2为终点,求1到2的最短距离,距离是1到2中所有的路径中的最大值。
     1 #include <iostream>
     2 #include <string.h>
     3 #include <stdio.h>
     4 #include <cmath>
     5 #include <vector>
     6 #include <queue>
     7 #define INF 0x3f3f3f3f
     8 using namespace std;
     9 const int N = 1010;
    10 int x[N], y[N], n;
    11 struct Nod {
    12     int to;
    13     double w;
    14 };
    15 vector<Nod> G[N];
    16 double d[N];
    17 typedef pair<double, int > P;
    18 double dis(int i, int j) {
    19     return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    20 }
    21 double dij() {
    22     priority_queue<P, vector<P>, greater<P> > que;
    23     for(int i = 1; i <= n; i ++) d[i] = INF;
    24     d[1] = 0;
    25     que.push(P(0,1));
    26     while(!que.empty()) {
    27         P p = que.top(); que.pop();
    28         int v = p.second;
    29         if(d[v] < p.first) continue;
    30         for(int i = 0; i < G[v].size(); i ++) {
    31             Nod e = G[v][i];
    32             if(d[e.to] > max(d[v],e.w)) {
    33                 d[e.to] = max(d[v],e.w);
    34                 que.push(P(d[e.to],e.to));
    35             }
    36         }
    37     }
    38     return d[2];
    39 }
    40 int main() {
    41     int k = 1;
    42     while(scanf("%d", &n)&&n) {
    43         for(int i = 1; i <= n; i ++) {
    44             scanf("%d %d",&x[i], &y[i]);
    45             G[i].clear();
    46         }
    47         for(int i = 1; i <= n; i ++) {
    48             for(int j = i+1; j <= n; j ++) {
    49                 double d = dis(i,j);
    50                 G[i].push_back((Nod){j,d});
    51                 G[j].push_back((Nod){i,d});
    52             }
    53         }
    54         printf("Scenario #%d
    ",k++);
    55         printf("Frog Distance = %.3f
    
    ",dij());
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    AE开发中Geometry到Polyline/Polygon的转换--转载
    asp.net MVC Views-----Controller传递数据方法
    百度翻译APi接口实现
    javascript添加删除行信息
    XMLDocument
    GDI绘制图像
    测试局域网内网络数据
    HL7 V2 分隔符
    IHE-PIX 备注
    数据库关键字 (Oracle, SQL Server, DB2)
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7278149.html
Copyright © 2011-2022 走看看