poj 2253 Frogger

http://poj.org/problem?id=2253

 

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>

using namespace std;

struct node
{
    int x,y;
}mem[1005];
bool visited[1005];
double dis[1005];
inline double disoftwopoints(int i,int j)
{
    return sqrt((double(mem[i].x)-mem[j].x)*(mem[i].x-mem[j].x)+(double(mem[i].y-mem[j].y))*(mem[i].y-mem[j].y));
}
int main()
{
    //freopen("date.txt" ,"r",stdin);
    int i,l=0,j,n;
    while(cin>>n)
    {
        ++l;
        if(!n)
        break;
        for(i=1;i<=n;i++)
        {
            cin>>mem[i].x>>mem[i].y;
        }
        for(i=1;i<=n;i++)
        {
            dis[i]=disoftwopoints(1,i);
        }
        memset(visited,false,sizeof(visited));
        visited[1]=true;
        for(i=0;i<n;i++)
        {
            double minf=30000.0;
            int k=0;
            for(j=1;j<=n;j++)
            {
                if(!visited[j]&&dis[j]<minf)
                {
                    k=j;minf=dis[j];
                }
            }
            if(k==2)
            break;
            visited[k]=true;
            for(j=1;j<=n;j++)
            {
                if(!visited[j]&&dis[j]>max(dis[k],disoftwopoints(k,j)))
                {
                    dis[j]=max(dis[k],disoftwopoints(k,j));
                }
            }
        }

        cout<<"Scenario #"<<l<<endl;
        printf("Frog Distance = %.3f\n\n",dis[2]); //这里是%.3f才可以

    }
    return 0;
}

你可能感兴趣的:(poj)