灰常开心的用Floyd变形写出来了。额。对米来说还是牺牲了一定的脑细胞的。然而。我发现。大牛们还可以神奇的用Kruskal求最大生成树的最小权值来写。也可以用Dijkatra变形来写。T_T。。。。555.。。。闪到米的24K钛合金防爆....

附Floyd代码:(一次AC哟)

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<map>
#define inf 0x1f1f1f1f
using namespace std;

int mapp[210][210];   // 两点之间的权值
int n, r, val;
char st[40], ed[40];
int tot = 0;
int i, j, k;
int ans[210][210];  // 两点之间的最小段的长度

int main()
{
    int cnt = 0;
    while (cin >> n >> r)
    {
        cnt++;
        map<string, int>m;
        tot = 1;
        m.clear();
        memset(mapp, inf, sizeof(mapp));
        if (n == 0 && r == 0)
        break;
        memset(ans, 0, sizeof(ans));
        for (int i=0; i<r; ++i)
        {
            cin >> st >> ed >> val;
            if (!m[st]) m[st] = tot++;
            if (!m[ed]) m[ed] = tot++;
            mapp[m[st]][m[ed]] = val;
            mapp[m[ed]][m[st]] = val;
            ans[m[st]][m[ed]] = val;
            ans[m[ed]][m[st]] = val;
        }
        for (k=1; k<=n; ++k)
        {
            for (i=1; i<=n; ++i)
            {
                for (j=1; j<=n; ++j)
                {
                    if (mapp[i][k] != inf && mapp[k][j] != inf && i!=j && j!=k && i!=k)
                    {
                        mapp[i][j] = mapp[i][k] + mapp[k][j];
                        ans[i][j] = max(ans[i][j], min(ans[i][k], ans[k][j])); // 这里刚开始用了min(mapp[i][k], mapp[k][j]).NO .
                        ans[j][i] = ans[i][j];
                    }
                }
            }
        }
        cin >> st >> ed;
        cout << "Scenario #" << cnt << endl;
        cout << ans[m[st]][m[ed]] << ' ' << "tons" << endl;
        cout << endl;
    }
    return 0;
}

 

posted on 2015-06-18 19:35  小小八  阅读(220)  评论(0编辑  收藏  举报