ZJU 1952 Heavy Cargo

最坏情况的输入操作次数: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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值