首页 > 其他 > 详细

poj 2263

时间:2014-08-11 23:56:53      阅读:527      评论:0      收藏:0      [点我收藏+]

 

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
#include <map>
int a[205][205];
int main(int argc, char *argv[])
{
int m,n,i,j,k,r,p=0;
string s1,s2;
while(cin>>n>>m&&(n||m))
{
map <string,int> ma;
k=0;
memset(a,0,sizeof(a));
for(i=0;i<m;i++)
{
cin>>s1>>s2>>j;
if(!ma.count(s1)) ma[s1]=k++;
if(!ma.count(s2)) ma[s2]=k++;
a[ma[s1]][ma[s2]]=j; a[ma[s2]][ma[s1]]=j;
}
cin>>s1>>s2;
for(r=0;r<k;r++)
for(i=0;i<k;i++)
for(j=0;j<k;j++)
a[i][j]=max(a[i][j],min(a[i][r],a[r][j]));
cout<<"Scenario #"<<++p<<endl<<a[ma[s1]][ma[s2]]<<" tons"<<endl<<endl;
}
return 0;
}

 

 

 

 

#include <iostream>
#include <stdio.h>
#include <string>
#include <map>
#include <string.h>
#include <algorithm>
#include <sstream>
using namespace std;
#define N 220
#define INF 10000000


map<string, int > g;
int n,m;
int mat[N][N];


void floyd()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if( mat[i][j] < min (mat[i][k],mat[k][j]) )
{
mat[i][j] = min(mat[i][k],mat[k][j]);
}
}


int main()
{

int tt=1;
string str,str1;
while(scanf("%d%d",&n,&m)&&(m+n))
{
memset( mat,0,sizeof(mat) );
int cnt=1,key;
for(int i=0 ; i < m ; i++)
{
cin>>str;
if(g[str]==0) { g[str]=cnt++; }

cin>>str1;
if(g[str1]==0) { g[str1]=cnt++; }

cin>>key;
mat[g[str]] [g[str1]]=mat[ g[str1] ][ g[str] ]=key;
}
floyd();
cin>>str>>str1;
printf("Scenario #%d\n",tt++);
printf("%d tons\n",mat[ g[str] ][ g[str1] ]);
printf("\n");

}
}

 

 

 

 

 

max( 最小重量 )


max( g[i][j], min(g[i][k],g[k][j] )

 

poj 2263,布布扣,bubuko.com

poj 2263

原文:http://www.cnblogs.com/2014acm/p/3905683.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!