HDU2923 Einbahnstrasse (Floyd)

Source: Internet
Author: User

Einbahnstrasse

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3263 Accepted Submission (s): 1018

Problem Descriptioneinbahnstra E (German for a one-way street) was a street on which vehicles should only move in one Direc tion. One reason for have one-way streets is to facilitate a smoother flow of traffic through crowded areas. This was useful in the city centers, especially old cities like Cairo and Damascus. Careful planning guarantees, that's you can get-to-any-location-starting from-any-point. Nevertheless, drivers must carefully plan their route in order to avoid prolonging their trips due to one-way streets. Experienced drivers know that there is multiple paths to travel between any and locations. There might be multiple roads between the same. Knowing the shortest between any and locations is a must! This was even more important if driving vehicles that was hard to maneuver (garbage trucks, towing trucks, etc.)
You just started a new job at a car-towing company. The company had a number of towing trucks parked at the company ' s garage. A tow-truck lifts the front or back wheels of a broken car in order to pull it straight back to the company ' s garage. You receive calls from various parts of the city about broken cars, that need to be towed. The cars has the towed in the same order as you receive the calls. Your job is to advise the Tow-truck drivers regarding the shortest the "in order" to "collect all broken cars" Company ' s garage. At the end of the ' Day ', you had to report to the management the distance traveled by the trucks. Inputyour program would be tested on one or more test cases. The first line of all test case specifies three numbers (N, C, and R) separated by one or more spaces. The city had N locations with distinct names and including the company ' s garage. C is the number of broken cars. R is the number of roads in the city. Note that 0 < N < 0<=c<, and R < 10000. The second line was made of C + 1 words, the first being the location of the company ' s garage, and the rest being the Locat Ions of the broken cars. A location is a word made of ten letters or less. Letter case is significant. After the second line, there'll is exactly R lines, each describing a road. A Road is described using one of these three formats:
A-v, B
A <-v-b
A <-v B
A and B are names of the different locations, while V was a positive integer (not exceeding) denoting the length of th E Road. The first format specifies a one-way street from location A to B, the second specifies a one-way street from B to a, whi Le the last specifies a two-way street between them. A, ' The arrow ', and B is separated by one or more spaces. The end of the test cases is specified with a line has three zeros (for N, C, and R.)

The test case in the example below is the same as the one in the.

Outputfor each test case, print the total distance traveled using the following format:
K. V
Where k is test Case number (starting at 1,) was a space, and V is the result. Sample Input4 2 5NewTroy midvale metrodalenewtroy <-20-> midvalemidvale--50-> Bakerlinenewtroy <-5--Bakerli Nemetrodale <-30-> Newtroymetrodale--5-> Bakerline0 0 0Sample Output1. 80 "Analysis" This problem data is not big, you can use the Floyd algorithm, input when the attention on the line (Whim want to do before the shortest short write a problem).
#include <iostream>#include<cstring>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<time.h>#include<string>#include<map>#include<stack>#include<vector>#include<Set>#include<queue>#defineINF 0x3f3f3f3f#defineMoD 1000000007typedefLong Longll;using namespacestd;Const intn= the+5; Map<string,int>MP;intn,c,r,w[ the][ the];voidFloyd () { for(intk=1; k<=n; k++)         for(intI=1; i<=n; i++)             for(intj=1; j<=n; J + +)            {                if(w[i][j]>w[i][k]+W[k][j]) w[i][j]=w[i][k]+W[k][j]; }}intMain () {Chara[ -],b[ -],t[ -]; Chard[1010][ the],ch2,ch1; intk,cas=1, KL;  while(SCANF ("%d%d%d", &n,&r,&c)! =EOF) {k=1; if(n==0&&r==0&&c==0) Break;        Mp.clear ();  for(intI=0; i< the; i++)             for(intj=0; j< the; J + +)                if(I==J) w[i][j]=0; Elsew[i][j]=inf;  for(intI=0; i<=r; i++) {scanf ("%s",&D[i]); if(mp[d[i]]==0) Mp[d[i]]=k++; }         for(intIi=0; ii<c; ii++) {scanf ("%s",&a); scanf ("%c-%d-%c",&ch1,&kl,&CH2); scanf ("%s",&b); if(mp[a]==0) mp[a]=k++; if(mp[b]==0) mp[b]=k++; intu=mp[a],v=Mp[b]; if(ch1=='<') w[v][u]=min (kl,w[v][u]); if(ch2=='>') w[u][v]=min (kl,w[u][v]);        } Floyd (); intsum=0;  for(intI=1; i<=r; i++) {sum+=w[mp[d[0]]][mp[d[i]]]+w[mp[d[i]]][mp[d[0]]]; } printf ("%d.%d\n", cas++, sum); }}
View Code

HDU2923 Einbahnstrasse (Floyd)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.