1575. Yekaterinburg Subway 2

系统 1605 0

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;

}


    

1575. Yekaterinburg Subway 2


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论