题目:

Einbahnstrasse

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1548    Accepted Submission(s): 428

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

You
just started a new job at a car-towing company. The company has 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 have
to be towed in the same order as you receive the calls. Your job is to
advise the tow-truck drivers regarding the shortest way in order to
collect all broken cars back in to the company's garage. At the end of
the day, you have to report to the management the total distance
traveled by the trucks.

 
Input
Your
program will be tested on one or more 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 with distinct 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,
the first being the location of the company's garage, and the rest being
the locations 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 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 two different locations, while v is a positive
integer (not exceeding 1000) denoting the length of the 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 , while the last specifies a
two-way street between them. A , ``the arrow", and B are separated by
one or more spaces. The end of the test cases is specified with a line
having three zeros (for N , C , and R .)

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

 
Output
For each test case, print the total distance 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
4 2 5
NewTroy Midvale Metrodale
NewTroy <-20-> Midval
Midvale --50-> Bakerline
NewTroy <-5-- Bakerline
Metrodale <-30-> NewTroy
Metrodale --5-> Bakerline
0 0 0
 
Sample Output
1. 80
 
  题意:给你衣服一幅图,上面有一些点,一些有向边,一些无向边,以及边权,给你一个起点,一些目的地,目的地上面有一些破车,每一次你只可以到一个目的地回收一辆破车,到达目的地以后要把破车送回起点,求最终走的路程是多少。
  代码敲出来以后各种卡,调试了好几遍以后终于把有的bug都去掉了,用c++交上去结果ce了,检查了很久发现原来少了个string的头文件,可是g++可以编译= =。加上去以后还是一直wa,后来瞄了一眼人家的题解,想起每一个目的地不止一辆破车,虽然这个一开始也想到,但是忽略了一次一辆拖车只可以拖一辆破车。然后把每个目的地的破车的数目乘上去以后就过了= =。
 
代码:
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#define INF 1000000000
#define MAX 110
using namespace std; map<string,int> M; int dis[MAX][MAX],amount[MAX],n; void Flyod()
{
int i,j,u;
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(dis[i][j]<=) dis[i][j]=INF;
if(i==j) dis[i][j]=;
}
}
for(u=;u<=n;u++)
{
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
int len=dis[i][u]+dis[u][j];
if(dis[i][j]>len) dis[i][j]=len;
}
}
}
/*
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(dis[i][j]<INF) printf("%d ",dis[i][j]);
else printf("INF ");
}
printf("\n");
}
*/
} int main()
{
int i,v,c,r,t,a,b,sum;
char ch[];
string s1,s2;
t=;
//freopen("data.txt","r",stdin);
while(scanf("%d %d %d",&n,&c,&r),(n+c+r))
{
//printf("%d %d %d\n",n,c,r);
t++;
c++;
M.clear();
memset(amount,,sizeof(amount));
n=;
for(i=;i<=c;i++)
{
cin>>s1;
if(M.count(s1)<=)
{
M[s1]=n++;
}
amount[M[s1]]++;
}
c=n-;
memset(dis,,sizeof(dis));
while(r--)
{
cin>>s1;
if(M.count(s1)<=) M[s1]=n++;
a=M[s1];
scanf("%s",ch);
cin>>s2;
if(M.count(s2)<=) M[s2]=n++;
b=M[s2];
sscanf(ch+,"%d",&v);
int len=strlen(ch);
if(ch[len-]=='>')
{
if(dis[a][b]== || dis[a][b]>v) dis[a][b]=v;
}
if(ch[]=='<')
{
if(dis[b][a]== || dis[b][a]>v) dis[b][a]=v;
}
}
n--;
Flyod();
sum=;
for(i=;i<=c;i++)
{
sum+=(dis[][i]+dis[i][])*amount[i];
}
printf("%d. %d\n",t,sum);
}
return ;
}

2923

 

HDU - 2923 - Einbahnstrasse的更多相关文章

  1. HDU 2923 Relocation(状压dp+01背包)

    题目代号:HDU2923 题目链接:http://poj.org/problem?id=2923 Relocation Time Limit: 1000MS Memory Limit: 65536K ...

  2. hdu 2923 map+Floyd 拉破车

    有向图 具体方向看箭头 从起点到指定城市拉破车,一个城市可能有多个破车,一次只能拉一辆破车 也就是到了指定地点后要回到起点 假如有100辆破车 但是只有一个城市有 就得在起点与这个城市间往返100次所 ...

  3. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  4. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  5. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  6. 【转】最短路&差分约束题集

    转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...

  7. 转载 - 最短路&差分约束题集

    出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548    A strange lift基础最短路(或bfs)★ ...

  8. 最短路&查分约束

    [HDU] 1548 A strange lift 根蒂根基最短路(或bfs)★ 2544 最短路 根蒂根基最短路★ 3790 最短路径题目 根蒂根基最短路★ 2066 一小我的观光 根蒂根基最短路( ...

  9. hdu 1596 find the safest road (最短路径)

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. webService总结(一)——使用CXF公布和调用webService(不使用Spring)

    CXF和Axis2是两个比較流行的webService框架,接下来我会写几篇博客简介怎样使用这两种框架. 首先,先简介一下CXF的使用. CXF公布webService有多种方法.这里我介绍三种: 1 ...

  2. luogu4218 [JSOI2008] 最小生成树计数

    题目大意 求一个加权无向图的最小生成树的个数.1<=n<=100; 1<=m<=1000,具有相同权值的边不会超过10条. 题解 命题1 由构成最小生成树的边的边权从小到大排序 ...

  3. hdoj--1027--Ignatius and the Princess II(dfs)

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  4. 批量梯度下降(Batch gradient descent) C++

    At each step the weight vector is moved in the direction of the greatest rate of decrease of the err ...

  5. Python 36 死锁现象和递归锁、信号量、Event事件、线程queue

    一:死锁现象和递归锁 所谓死锁: 是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这些永远 ...

  6. 一种压缩图片的方法---Machine learning 之 K-Means

    背景描述: RGB编码:对于一个直接用24bit表示每一个而像素的图像来说,每一个pixel使用8-bit无符号整数(0-255)来表示红or绿or蓝. 压缩目的: 将128x128大小的图片由原来的 ...

  7. SQLServer2008 字符串函数一览表

    /* 字符串函数 (PS.索引都从1开始计算)*/ /* 指定字符(或字符串)A.字符串B.起始索引.获得A在B中的索引值.*/select Charindex('d','abcdefg',0) -- ...

  8. css中background-clip属性的作用

    background-clip属性的通俗作用就是指定元素背景所在的区域,有四种取值 1.border-box border-box是默认值,表示元素的背景从border区域(包括border)以内开始 ...

  9. SEO之如何做301转向

    1.如果网站使用的是(Linux+Apache+MySQL+PHP)主机,可以使用.htaccess文件做301转向 比如把/index.html 301转向到http://www.xinlvtian ...

  10. js-学习方法

    1:多实践,找例子,看别人是如何实现的,然后自己去实现,然后谷歌百度,最后总结. 2:如何读js英文书:不是自己不会读,是被吓着了.自己吓自己. 英文不好的话,先不要挨着排的从头到尾读. 应该首先读目 ...