B - Frogger 图论

#include"stdio.h"
#include"stdlib.h"
#include"math.h"
#include"string.h"
double diss(int x1,int x2,int y1,int y2)
{
    int  dis=0;
    return (sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));   
}
int main()
{
   int x,y,n,map[1010][1010];
   double  sum[1010]={0},dis[1010]={0};
   while(scanf("%d",&n)!=EOF)
   {
      while(n-->0)
      {
           for(int i=0;i<n;i++)
           {
                scanf("%d%d",&x,&y);           
                map[0][i]=x;
                map[i][1]=y;
             for(int j=0;j<2;j++)
                  dis[i]=diss(map[0][i],map[0][j],map[i][1],map[j][1]);
             for(int j=0;j<n;j++)
             {
               for(int k=0;k<n;k++)
               {     
                 dis[i]+dis[j]>dis[i]+dis[k];
                 sum[i]+=dis[i]+dis[k];       
               }
             }                   
           }
            for(int i=0;i<n;i++)
            {
                getchar();
                printf("Scenario #i\n");
                printf("Frog  Distance=%.3lf\n",sum[n]);
            }
      }
   } 
    //system("pause");
    return 0;
}

posted @ 2011-08-11 16:51  bcy  阅读(120)  评论(0编辑  收藏  举报