zoukankan      html  css  js  c++  java
  • 1575. Yekaterinburg Subway 2 夜

    http://acm.timus.ru/problem.aspx?space=1&num=1575

    这么狗血的题也有呀 无语了 

    一般都是给出数据然后建图 这题都好  直接给图 自己弄去吧  幸亏有人给了数据 直接copy过来处理一下就可以了

    简单 floyd 

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<map>
    #include<vector>
    #include<stack>
    #include<set>
    #include<map>
    #include<queue>
    #include<algorithm>
    #include<cmath>
    #define LL long long
    #define sint short int
    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    using namespace std;
    const int N=105;
    const int INF=0x3f3f3f3f;
    string s[10][N]={
        {"7_klyuchey", "Sortirovochnaya", "China_town", "Zarechny", "City", "1905_year_square", "Kuybyshevskaya",
            "Sibirskaya", "Siniye_kamni", "Lechebnaya", "Varshavskaya", "Kompressornaya", "Koltsovo"},
        {"Zelyony_ostrov", "Tatishchevskaya", "Verh_Isetskaya", "Kommunarov_square", "1905_year_square",
            "Teatralnaya", "Vostochnaya", "Vtuzgorodok", "Kamennye_palatki", "University"},
        {"MEGA", "Metallurgov", "Kraulya", "Central_stadium", "Moskovskaya", "1905_year_square",
            "Shevchenko", "Pionerskaya", "Turbinnaya", "Elmash", "Taganskaya"},
        {"Akademicheskaya", "Yugo_zapadnaya", "Volgogradskaya", "Posadskaya", "Geologicheskaya", "Teatralnaya",
            "Gagarinskaya", "Komsomolskaya", "Shefskaya", "Ozyornaya", "Italyanskaya", "Kalinovskaya"},
        {"Sovhoznaya", "Voennaya", "Aviatsionnaya", "Dvorets_sporta", "Geologicheskaya",
            "Kuybyshevskaya", "Vostochnaya", "Gagarinskaya", "Vilonovskaya"},
        {"Keramicheskaya", "Vtorchermet", "Samolyotnaya", "Botanicheskaya", "Parkovaya", "Mayakovskaya",
            "Oborony_square", "Kuybyshevskaya", "Teatralnaya", "Shevchenko", "Uralskaya", "Zvezda",
            "I_Pyatiletki_square", "Pobedy"},
        {"Himmash", "Nizhne_Isetskaya", "Uktusskie_Gory", "Shcherbakovskaya", "Botanicheskaya", "Chkalovskaya",
            "Bazhovskaya", "Geologicheskaya", "1905_year_square", "Dinamo", "Uralskaya", "Mashinostroiteley",
            "Uralmash", "Prospekt_Kosmonavtov", "Bakinskih_Komissarov"},
        {"Moskovskaya", "Kommunarov_square", "City", "Uralskaya", "Pionerskaya", "Gagarinskaya", "Vtuzgorodok",
            "Sibirskaya", "Oborony_square", "Bazhovskaya", "Dvorets_sporta", "Posadskaya", "Moskovskaya"}
    };
    int L[10]={13,10,11,12,9,14,15,13};
    int a[N];
    map<string,int>mt;
    int dist[N][N];
    int main()
    {
        //freopen("data.in","r",stdin);
        for(int i=0;i<N;++i)
        for(int j=0;j<N;++j)
        dist[i][j]=INF;
        int k=0;
        for(int i=0;i<8;++i)
        {
            for(int j=0;j<L[i];++j)
            {
                if(mt.find(s[i][j])==mt.end())
                {
                    mt[s[i][j]]=k++;
                }
                a[j]=mt[s[i][j]];
            }
            for(int j=1;j<L[i];++j)
            {
                dist[a[j]][a[j-1]]=1;
                dist[a[j-1]][a[j]]=1;
            }
            if(i==7)
            {dist[a[0]][a[L[i]-1]]=1;dist[a[L[i]-1]][a[0]]=1;}
        }
        for(int i=0;i<k;++i)
        dist[i][i]=0;
        for(int l=0;l<k;++l)
        for(int i=0;i<k;++i)
        for(int j=0;j<k;++j)
        if(dist[i][l]+dist[l][j]<dist[i][j])
        dist[i][j]=dist[i][l]+dist[l][j];
        int n;
        cin>>n;
        while(n--)
        {
            string s1,s2;
            cin>>s1>>s2;
            cout<<dist[mt[s1]][mt[s2]]<<endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    long和Long的区别
    C语言的变量的内存分配
    Java蓝桥杯 算法提高 九宫格
    Java实现 蓝桥杯算法提高金明的预算方案
    Java实现 蓝桥杯 算法提高 新建Microsoft world文档
    Java实现 蓝桥杯 算法提高 快乐司机
    Java实现 蓝桥杯 算法提高 三角形
    Java实现 蓝桥杯 算法提高 三角形
    Java实现 蓝桥杯 算法提高 三角形
    Java实现 蓝桥杯 算法提高 三角形
  • 原文地址:https://www.cnblogs.com/liulangye/p/2873770.html
Copyright © 2011-2022 走看看