题意:题意求从第一点到其它点的最短路中最大的。
很明显,很暴力。注意输入,当然有个函数很好用atoi将字符串转换为数字 。头文件
#include
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define inf 0x3f3f3f3f
using namespace std;
int n,ans;
int gragh[105][105];
void floyd()
{
ans = 0;
for(int k = 1;k <= n; k++)
for(int i = 1;i <= n; i++)
for(int j = 1;j <= n; j++)
gragh[i][j] = min(gragh[i][j],gragh[i][k] + gragh[k][j]);
for(int i = 2;i <= n; i++)
if(gragh[1][i] > ans)
ans = gragh[1][i];
}
int main()
{
// freopen("in.txt","r",stdin);
while(scanf("%d",&n) != EOF){
memset(gragh,inf,sizeof(gragh));
char s[8];
for(int i = 2;i <= n; i++){
for(int j = 1;j < i; j++){
scanf("%s",s);
if(s[0] != 'x')
gragh[i][j] = gragh[j][i] = atoi(s);
}
}
floyd();
printf("%d\n",ans);
}
return 0;
}