hdu 2923 floyd+map容器

原创 2016年05月31日 14:57:39


TimeLimit: 2000/1000 MS (Java/Others)    Memory Limit:32768/32768 K (Java/Others)
Total Submission(s): 3079    Accepted Submission(s): 960

Problem Description

Einbahnstra e(German for a one-way street) is a street on which vehicles should only move inone direction. One reason for having one-way streets is to facilitate asmoother flow of traffic through crowded areas. This is useful in city centers,especially old cities like Cairo and Damascus. Careful planning guarantees thatyou can get to any location starting from any point. Nevertheless, drivers mustcarefully plan their route in order to avoid prolonging their trip due toone-way streets. Experienced drivers know that there are multiple paths totravel between any two locations. Not only that, there might be multiple roadsbetween the same two locations. Knowing the shortest way between any twolocations is a must! This is even more important when driving vehicles that arehard to maneuver (garbage trucks, towing trucks, etc.)

You just started a new job at a car-towing company. The company has a number oftowing trucks parked at the company's garage. A tow-truck lifts the front orback wheels of a broken car in order to pull it straight back to the company'sgarage. You receive calls from various parts of the city about broken cars thatneed to be towed. The cars have to be towed in the same order as you receivethe calls. Your job is to advise the tow-truck drivers regarding the shortestway in order to collect all broken cars back in to the company's garage. At theend of the day, you have to report to the management the total distancetraveled by the trucks.




Your program will be tested on one ormore test cases. The first line of each test case specifies three numbers (N ,C , and R ) separated by one or more spaces. The city has N locations withdistinct names, 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 < 100 , 0<=C< 1000 , and R < 10000 . The second line is made of C + 1 words, thefirst being the location of the company's garage, and the rest being thelocations of the broken cars. A location is a word made of 10 letters or less.Letter case is significant. After the second line, there will be exactly Rlines, each describing a road. A road is described using one of these threeformats:

A -v -> B
A <-v - B
A <-v -> B

A and B are names of two different locations, while v is a positive integer(not exceeding 1000) denoting the length of the road. The first formatspecifies a one-way street from location A to B , the second specifies aone-way street from B to A , while the last specifies a two-way street betweenthem. A , ``the arrow", and B are separated by one or more spaces. The endof the test cases is specified with a line having three zeros (for N , C , andR .)

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




For each test case, print the totaldistance traveled using the following format:

k . V

Where k is test case number (starting at 1,) is a space, and V is the result.



Sample Input

42 5

NewTroyMidvale Metrodale

NewTroy   <-20-> Midvale

Midvale   --50-> Bakerline

NewTroy    <-5-- Bakerline

Metrodale<-30-> NewTroy

Metrodale  --5-> Bakerline

00 0



Sample Output








分析:从起点到某地,然后在倒过来   求最短路的和。


同样的用map容器  构造一个有向图  就清楚了


#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#define INF 0x3f3f3f3f
#define MAX 1000
using namespace std;
int vis[MAX],dis[MAX];
int map1[MAX][MAX];
char rr[1001][100];
int n,m,C;
void floyd()
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                if(map1[i][j] > map1[i][k]+map1[k][j])
                    map1[i][j] = map1[i][k]+map1[k][j];

int main()
    int case1 = 1;
        int ans = 1;
        for(int i = 0; i <= C; i++)
                s[rr[i]] = ans++;
        for(int i = 0; i < 110; i++)
            for(int j = 0; j < 110; j++)
                map1[i][j] = INF;
            map1[i][i] = 0;
        char p[31],q[31];
        char a[31];
        for(int i = 0; i < m; i++)
            if(!s[p]) s[p] = ans++;
            if(!s[q]) s[q] = ans++;
            int len = strlen(a);
            int value = 0,flag = 1;
            for(int j = len - 3; j > 1; j--)
                value+=(a[j] - 48)*flag;
            if(map1[s[p]][s[q]] > value&&a[0] == '<')
                map1[s[p]][s[q]] = value;
            if(map1[s[q]][s[p]] > value&&a[len-1] == '>')
                map1[s[q]][s[p]] = value;
        /**for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                printf("%d ",map1[i][j]);
        printf("%d. ",case1++);
        int sum = 0;
        for(int i = 1; i <= C; i++)
            sum+=map1[s[rr[0]]][s[rr[i]]] + map1[s[rr[i]]][s[rr[0]]];
    return 0;


hdu 2923 最短路(Floyd)

Problem Description Einbahnstra e (German for a one-way street) is a street on which vehicles shou...
  • u010736393
  • u010736393
  • 2015年04月18日 14:25
  • 455

hdu 1495 非常可乐 BFS+倒水问题

传送门:[](http://acm.hdu.edu.cn/showproblem.php?pid=1495hdu 1495 非常可乐) 题目是中文的没有什么理解问题解题思路先来把问题特殊化,假如我们...
  • woshinannan741
  • woshinannan741
  • 2016年07月11日 22:42
  • 440

hdu2235 机器人的容器

题意: 机器人的容器 Time Limit: 3000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To...
  • u013761036
  • u013761036
  • 2014年04月15日 21:33
  • 453

POJ 2923 状态压缩

这题不难,但过得人不多啊,POJ才不到600人过。。。。做的时候也比较顺利,仅仅PE了一次。 题意,有两辆车,容量分别为V1,V2,每次要运一定的物品到新家,经过几次后,把所有物品都运到新家,问最少...
  • liverpippta
  • liverpippta
  • 2013年05月28日 18:41
  • 591


题目链接:点击打开链接 这个题目其实很简单,就是各种坑。 1.同一个地方破车可能有多辆。 2.每次拖完一辆破车必须回来,不能全部一次性拖完所有的....//一开始题意弄错了在这个地方纠结了很久 ...
  • u013548531
  • u013548531
  • 2014年12月02日 08:44
  • 195

HDU 题目分类

基础题:1000、1001、1004、1005、1008、1012、1013、1014、1017、1019、1021、1028、1029、 1032、1037、1040、1048、1056、1058...
  • qq_28236309
  • qq_28236309
  • 2015年08月20日 23:09
  • 12121

STL容器-----HDU 水果

很久没写博客了,也是很久没有抽出 时间来编程,刚开学还是先适应了一下课程,幸好一周之内有几天是只有一节课的。这半年还是按照自己的计划去练习,第一个月是STL和一些简单的数学题,来一遍把以前的专题都复习...
  • u010092734
  • u010092734
  • 2013年09月17日 07:18
  • 1045


欧拉回路 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi...
  • hpulw
  • hpulw
  • 2016年03月15日 12:38
  • 238

hdu5444 Elven Postman(二叉树遍历)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5444 题目大意:给出一颗二叉树的先序遍历,默认的中序遍历是1.、2、……n。给出q个询问,询...
  • aaaaacmer
  • aaaaacmer
  • 2015年09月14日 17:00
  • 1259

HDU 2102 A计划(深搜)

Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的...
  • Lcc_2016
  • Lcc_2016
  • 2016年07月15日 16:43
  • 612
您举报文章:hdu 2923 floyd+map容器