关闭

ZJU 1952 Heavy Cargo

标签: struct
927人阅读 评论(0) 收藏 举报
分类:

最坏情况的输入操作次数:20000 *200 = 4,000,000

为了写起来方便,直接FLOYD搞定,200^3 = 8, 000,000

[CODE]
#include <stdio.h>
#include <string.h>

const int M = 205 ;
struct CITY {
 char name[35] ;
} city[M] ;
int value[M][M], nCount ;

int GetCityPos ( char p[] )
{
 int i ;
 for ( i = 0; i < nCount; i++ )
 {
  if ( strcmp ( p, city[i].name ) == 0 )
   return i ;
 }
 strcpy ( city[nCount].name, p ) ;
 nCount ++ ;
 return nCount - 1 ;
}

int main()
{
 int nCityNum, nPathNum, cases = 0 ;
 while ( scanf ( "%d %d", &nCityNum, &nPathNum ) && nCityNum )
 {
  memset ( value, 0, sizeof(value) ) ;
  char ACity[35], BCity[35] ;
  nCount = 0 ;
  int i, j, k, load ;
  getchar () ;
  for ( i = 0; i < nPathNum; i++ )
  {
   scanf ( "%s %s %d", ACity, BCity, &load ) ;
   getchar() ;
   int a = GetCityPos ( ACity ) ;
   int b = GetCityPos ( BCity ) ;
   value[a][b] = value[b][a] = load ;
  }
  for ( k = 0; k < nCityNum; k++ )
  {
   for ( i = 0; i < nCityNum; i++ )
   {
    for ( j = 0; j < nCityNum; j++ )
    {
     int temp = value[i][k] > value[k][j] ? value[k][j] : value[i][k] ;
     if ( temp > value[i][j] )
      value[i][j] = temp ;
    }
   }
  }
  scanf ( "%s %s", ACity, BCity ) ;
  int a = GetCityPos ( ACity ) ;
  int b = GetCityPos ( BCity ) ;
  printf ( "Scenario #%d/n", ++cases ) ;
  printf ( "%d tons/n/n", value[a][b] ) ;
 }
 return 0;
}

[/CODE]

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:79888次
    • 积分:1019
    • 等级:
    • 排名:千里之外
    • 原创:16篇
    • 转载:24篇
    • 译文:0篇
    • 评论:2条
    最新评论
    牛博
    影视资源