poj 2253

/*
         _...---.._
       ,'          ~~"--..
      /                   ~"-._
     /                         ~-.
    /              .              `-.
    \             -.\                `-.
     \              ~-.                 `-.
  ,-~~\                ~.
 /     \                 `.
.       \                  `.
|        \                   .
|         \                   \
 .         `.                  \
             \                  \
  `           `.                 \
   `           \.                 \
    `           \`.                \
     .           \ -.               \
     `               -.              \
      .           `    -              \  .
      `            \    ~-             \
       `            .     ~.            \
        .            \      -_           \
        `                     -           \
         .            |        ~.          \
         `            |          \          \
          .           |           \          \
          `           |            `.         \
           `          `              \         \
            .          .              `.        `.
            `          :                \         `.
             \         `                 \          `.
              \         .                 `.         `~~-.
               \        :                   `         \   \
                .        .                   \         : `.\
                `        :                    \        |  | .
                 \        .                    \       |  |
                  \       :                     \      `  |  `
                   .                             .      | |_  .
                   `       `.                    `      ` | ~.;
                    \       `.                    .      . .
                     .       `.                   `      ` `
                     `.       `._.                 \      `.\
                      `        <  \                 `.     | .
                       `       `   :                 `     | |
                        `       \                     `    | |
                         `.     |   \                  :  .' |
"Are you crying? "        `     |    \                 `_-'  |
  "It's only the rain."  :    | |   |                   :    ;
"The rain already stopped."`    ; |~-.|                 :    '
  "Devils never cry."       :   \ |                     `   ,
                            `    \`                      :  '
                             :    \`                     `_/
                             `     .\       "For we have none. Our enemy shall fall."
                              `    ` \      "As we apprise. To claim our fate."
                               \    | :     "Now and forever. "
                                \  .'  :    "We'll be together."
                                 :    :    "In love and in hate"
                                 |    .'
                                 |    :     "They will see. We'll fight until eternity. "
                                 |    '     "Come with me.We'll stand and fight together."
                                 |   /      "Through our strength We'll make a better day. "
                                 `_.'       "Tomorrow we shall never surrender."
     sao xin*/
#include <vector>
#include <iostream>
#include <string>
//#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include<functional>
#define INF 0xfffffff
#define eps 1e-6
#define LL long long


using namespace std;
const int N=1e3+5;
const int maxx=1e4+5;
const double q = (1 + sqrt(5.0)) / 2.0;   // 黄金分割数
/*
std::hex    <<16进制   cin>>std::hex>>a>>std::hex>>b
cout.setf(ios::uppercase);cout<<std::hex<<c<<endl;
b=b>>1; 除以2 二进制运算


//f[i]=(i-1)*(f[i-1]+f[i-2]);   错排
/ for (int i=1; i<=N; i++)
        for (int j=M; j>=1; j--)
        {
            if (weight[i]<=j)
            {
                f[j]=max(f[j],f[j-weight[i]]+value[i]);
            }
        }
priority_queue<int,vector<int>,greater<int> >que3;//注意“>>”会被认为错误,
priority_queue<int,vector<int>,less<int> >que4;////最大值优先
//str
//tmp
//vis
//val
//cnt     2486   hdu 3790最短路径
*/
int n,Nn;
double map[N][N];
double dis[N];
int vis[N];
double x[N],y[N];
double dist(double x,double y,double x1,double y1)
{
    return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
}
double max(double a,double b)
{
    return a>b?a:b;
}
void Dijkstra(int start)
{
    double minimum,min;
    int k,j,i;
    memset(vis,0,sizeof(vis));
    for(i=1;i<=n;i++)
        dis[i]=map[start][i];
    vis[start]=true;


    minimum=0;
    for(i=1;i<n;i++)
    {
        min=N;
        for(j=1;j<=n;j++)
        if(dis[j]<min&&!vis[j])
            {
                min=dis[j];
                k=j;
            }
    if(i==1)
        minimum=min;


    vis[k]=true;
    if(k==2)
    {
        cout<<"Scenario #"<<Nn<<endl;
        cout<<"Frog Distance = ";
        printf("%.3f\n\n",dis[2]);
        break;
    }
    for(j=1;j<=n;j++)
    if(dis[j]>max(dis[k],map[k][j])&&!vis[j])
        {
            dis[j]=max(dis[k],map[k][j]);
        }
    }
}
int main()
{
    int i,j;
    Nn=0;
    while(cin>>n,n)
    {
        for(i=1;i<=n;i++)
            cin>>x[i]>>y[i];


        for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            map[i][j]=N;


        for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            {
                map[i][j]=dist(x[i],y[i],x[j],y[j]);
                map[j][i]=map[i][j];
            }
            Nn++;
        Dijkstra(1);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值