POJ 2253 Frogger

來源:互聯網
上載者:User
//Time 63ms, Memory 572K
#include<iostream>  #include<math.h>  #include<iomanip>  using namespace std;    class coordinate  {  public:      double x,y;  }point[201];    double path[201][201];   //兩點間的權值    int main(void)  {      int i,j,k;        int cases=1;      while(cases)      {          /*Read in*/            int n;   //numbers of stones;          cin>>n;          if(!n)break;            for(i=1;i<=n;i++)              cin>>point[i].x>>point[i].y;            /*Compute the weights of any two points*/            for(i=1;i<=n-1;i++)              for(j=i+1;j<=n;j++)              {                  double x2=point[i].x-point[j].x;                  double y2=point[i].y-point[j].y;                  path[i][j]=path[j][i]=sqrt(x2*x2+y2*y2);  //雙向性              }            /*Floyd Algorithm*/            for(k=1;k<=n;k++)    //k點是第3點              for(i=1;i<=n-1;i++)    //主要針對由i到j的鬆弛,最終任意兩點間的權值都會被分別鬆弛為最大跳的最小(但每個兩點的最小不一定相同)                  for(j=i+1;j<=n;j++)                      if(path[i][k]<path[i][j] && path[k][j]<path[i][j])    //當邊ik,kj的權值都小於ij時,則走i->k->j路線,否則走i->j路線                          if(path[i][k]<path[k][j])               //當走i->k->j路線時,選擇max{ik,kj},只有選擇最大跳才能保證連通                              path[i][j]=path[j][i]=path[k][j];                          else                              path[i][j]=path[j][i]=path[i][k];            cout<<"Scenario #"<<cases++<<endl;          cout<<fixed<<setprecision(3)<<"Frog Distance = "<<path[1][2]<<endl;          //fixed用固定的小數點位元來顯示浮點數(包括小數位全為0)          //setprecision(3)設定小數位元為3          cout<<endl;      }      return 0;  }  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.