zoukankan      html  css  js  c++  java
  • Heavy Cargo

    Heavy Cargo

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    Description

    Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their latest model, the Godzilla V12, is so big that the amount of cargo you can transport with it is never limited by the truck itself. It is only limited by the weight restrictions that apply for the roads along the path you want to drive. 

    Given start and destination city, your job is to determine the maximum load of the Godzilla V12 so that there still exists a path between the two specified cities. 

    Input

    The input will contain one or more test cases. The first line of each test case will contain two integers: the number of cities n (2<=n<=200) and the number of road segments r (1<=r<=19900) making up the street network. 
    Then r lines will follow, each one describing one road segment by naming the two cities connected by the segment and giving the weight limit for trucks that use this segment. Names are not longer than 30 characters and do not contain white-space characters. Weight limits are integers in the range 0 - 10000. Roads can always be travelled in both directions. 
    The last line of the test case contains two city names: start and destination. 
    Input will be terminated by two values of 0 for n and r.

    Output

    For each test case, print three lines: 
    • a line saying "Scenario #x" where x is the number of the test case 
    • a line saying "y tons" where y is the maximum possible load 
    • a blank line

    Sample Input

    4 3
    Karlsruhe Stuttgart 100
    Stuttgart Ulm 80
    Ulm Muenchen 120
    Karlsruhe Muenchen
    5 5
    Karlsruhe Stuttgart 100
    Stuttgart Ulm 80
    Ulm Muenchen 120
    Karlsruhe Hamburg 220
    Hamburg Muenchen 170
    Muenchen Karlsruhe
    0 0
    

    Sample Output

    Scenario #1
    80 tons
     
    Scenario #2
    170 tons
    
     这是一道简单的最短路问题,但这道题的坑点是用number代表string,自然用map<string, int>;值得注意的是: map初始化都为0,导致端点不能用0表示!然后是多组数据测试中,map不需要初始化!
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<map>
    #include<string>
    using namespace std;
    int dis[205][205];
    map<string, int> G;
    char from[10005];
    char to[10005];
    int n;
    void init(){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                dis[i][j] = 0;
            }
        }
    }
    int floyd(int x,int y){
        for(int k = 1; k <= n; k++){
            for(int i = 1; i <= n; i++){
                for(int j = 1; j <= n; j++){
                    if(dis[i][k] > dis[i][j] && dis[k][j] > dis[i][j]){
                        dis[i][j] = min(dis[i][k], dis[k][j]);
                    }
                }
            }
        }
        printf("%d tons
    
    ",dis[x][y]);
    }
    int main(){
        int m,cas = 0;
        while(~scanf("%d%d",&n,&m)){
            if(n == 0 && m == 0)
                break;
            init();
            int cnt = 1;
            for(int i = 0; i < m; i++){
                int d;
                scanf("%s%s%d",from,to,&d);
                if(G[from] == 0)
                    G[from] = cnt++;
                if(G[to] == 0)
                    G[to] = cnt++;
                dis[G[from]][G[to]] = d;
                dis[G[to]][G[from]] = d;
            }
            scanf("%s%s",from,to);
            int x = G[from];
            int y = G[to];
            printf("Scenario #%d
    ",++cas);
            floyd(x,y);
        }
        return 0;
    }
  • 相关阅读:
    ASCII码对照表
    createPopup 超链接
    说说回车键触发表单提交的问题
    linux下配java环境的小结
    spring bind checkbox 传递值问题
    用Common validator为springMVC做验证时遇到的一个问题小记
    [转载]对android LinearLayout中layout_weight属性使用初探
    linux下tomcat启动正常,但用http://22.22.33.33:8080却访问不了,防火墙的设置问题
    Java 遍历Map时 删除元素
    ftp用户登录时不能进自己的目录,被拒绝登录的解决方法
  • 原文地址:https://www.cnblogs.com/ACMessi/p/4850280.html
Copyright © 2011-2022 走看看