zoukankan      html  css  js  c++  java
  • poj 2263

    #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 ",tt++);
    printf("%d tons ",mat[ g[str] ][ g[str1] ]);
    printf(" ");

    }
    }

    max( 最小重量 )


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

  • 相关阅读:
    p1706 全排列
    2089烤鸡(类似于选数问题)
    1036选数
    bfs
    A-E
    A-3
    百题A-2
    百题A-1
    二级概念题
    随记
  • 原文地址:https://www.cnblogs.com/2014acm/p/3905683.html
Copyright © 2011-2022 走看看