zoukankan      html  css  js  c++  java
  • HDU 最短路

    #include<iostream>
    #define INF 200000
    using namespace std;
    int max(int a,int b){return a>b?a:b;}
    int min(int a,int b){return a<b?a:b;}
    int map[1002][1002],N,M;
    int findmap(int sta,int end){
        int t;
        if(sta>end){t=end;end=sta;sta=t;}
        return map[sta][end];
    }
    void setmap(int sta,int end,int val){
        int t;
        if(sta>end){t=end;end=sta;sta=t;}
        if(sta==end){map[sta][end]=0;return;}
        map[sta][end]=val;
    }
    int main(){
        int a,b,c;
        cin>>N>>M;
        while(N!=0){
            for(int yy=0;yy<=N+5;yy++){
                for(int xx=0;xx<=N+5;xx++){
                    setmap(xx,yy,INF);
                }
            }
            for(int i=0;i<M;i++){
                cin>>a>>b>>c;
                setmap(a,b,c);
            }
            for(int mid=1;mid<=N;mid++){
                for(int sta=1;sta<=N;sta++){
                    for(int end=1;end<=N;end++){
                        a=findmap(sta,end);
                        b=findmap(sta,mid)+findmap(mid,end);
                        setmap(sta,end,min(a,b));
                    }
                }
            }
            
            cout<<map[1][N]<<endl;
            cin>>N>>M;
        }
        return 0;
    
    }

    http://acm.hdu.edu.cn/diy/contest_showproblem.php?pid=1001&cid=36602

  • 相关阅读:
    ORM框架
    优酷项目1
    新年第一天
    前端第十天
    前端第九天
    前端第八天
    前端第七天
    前端第六天
    前端第五天
    月亮与六便士
  • 原文地址:https://www.cnblogs.com/forwhat00/p/13245914.html
Copyright © 2011-2022 走看看