POJ 2253 Frogger

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   os   sp   for   on   

 題目連結:

poj.org/problem?id=2253

題目大意:

Freddy Frog 坐在湖中的一個石頭上, 突然的他注意到 Fiona Frog 坐在另一個石頭上, Freddy Frog 要去拜訪 Fiona Frog , 但是水很髒,而且有遊客的防晒霜漂上面, 為了避免遊泳過去他只能跳過去。

不幸的是Fiona 所在的石頭不在他跳躍的範圍內,因此他只能跳躍幾個其他的石頭到達 Fiona 所在的石頭, 這個青蛙的跳躍有個極大的距離 和 極小距離,  明顯的 在他跳躍的路上, 最長距離不能超過他的跳躍極限。

給你所有石頭在湖裡的座標, 你的任務是計算 兩個人所在石頭的距離。

輸入:

第一行 一個 n 代表石頭的個數, 第一個石頭 Freddy 的位置,第二個石頭 Fiona 的位置,  其餘的n-2個石頭是空的, 給你每個點的座標, 要求的是找出 一條路徑, 要你求這個路上的兩個石頭的最長距離,在所有路徑中最短。

題目分析:

這道題目其實就是最短求最大邊, 以前有做過此類題目。 運用SPFA 就直接寫了

注意: 提交的時候請用 C++ 別用G++

 

#include <iostream>#include <cstdlib>#include <cstdio>#include <algorithm>#include <vector>#include <queue>#include <cstring>#include <cmath>using namespace std;#define INF 0xfffffff#define maxn 300struct Point{    double x, y;};double Len(Point A, Point B){    return sqrt( (A.x-B.x) * (A.x-B.x) + (A.y-B.y)*(A.y-B.y) );}int n;double dist[maxn];double G[maxn][maxn];bool vis[maxn];double Spfa(){    int P = 1;    queue<int> Q;        Q.push(P);    while( !Q.empty() )    {        P = Q.front();        Q.pop();        vis[P] = false;        for(int i=1; i<=n; i++)        {            if(dist[i] > max(dist[P],G[P][i]) )            {                dist[i] = max(dist[P],G[P][i]);                if( !vis[i] )                {                    vis[i] = true;                    Q.push(i);                }            }        }    }    return dist[2];}void Init(){    for(int i=1; i<=n; i++)    {        dist[i] = INF;        vis[i] = false;        for(int j=1; j<=n; j++)            G[i][j] = INF;    }    dist[1] = 0;}int main(){    Point P[maxn];    int cas = 1;    while(scanf("%d", &n), n)    {        Init();        for(int i=1; i<=n; i++)        {            scanf("%lf%lf",&P[i].x,&P[i].y);        }        for(int i=1; i<=n; i++)        {            for(int j=1; j<=i; j++)            {                G[i][j] = Len(P[i],P[j]);                G[j][i] = G[i][j];            }        }        double ans = Spfa();        printf("Scenario #%d\n",cas ++);        printf("Frog Distance = %.3lf\n\n", ans);    }    return 0;}

 

POJ 2253 Frogger

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.