Einbahnstrasse
Einbahnstrasse |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
| Total Submission(s): 124 Accepted Submission(s): 54 |
|
Problem Description
Einbahnstra
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 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 |
|
Sample Output
1. 80 |
|
Source
2008 ANARC
|
|
Recommend
lcy
|
/*
求从总公司出发按顺序访问各个点然后回到公司的最小距离 Floyd 是固定松弛点在放缩,想错了
floy算法最简便
*/
#include<bits/stdc++.h>
#define N 105
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
int n,c,m,cur;
int mapn[N][N];
map<string,int>ma;
char city[][N],u[N],v[N],opl,opr;
int val;
/*
void floyd(){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=n;k++){
mapn[i][j]=min(mapn[i][j],mapn[i][k]+mapn[k][j]);
}
}
}
}
*/
/*
手写模板错了,应该固定松弛的点然后,在更新状态
*/
void floyd()
{
int i,j,k;
for(i = ; i<=n; i++)
for(j = ; j<=n; j++)
for(k = ; k<=n; k++)
if(mapn[j][i]+mapn[i][k]<mapn[j][k])
mapn[j][k] = mapn[j][i]+mapn[i][k];
} void init(){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
mapn[i][j]=INF;
}
}
}
int main(){
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
int Case=;
while(scanf("%d%d%d",&n,&c,&m)!=EOF&&(n+c+m)){
init();
ma.clear();
for(int i=;i<=c;i++){
scanf("%s",city[i]);
//cout<<city<<" ";
}
//cout<<endl;
int len=;//表示结点(这个地方坐标必须从1开始,因为map中没有的东西会返回的键值是0)
for(int i=;i<m;i++){
scanf("%s %c-%d-%c %s",u,&opl,&val,&opr,v);
//printf("%s %c-%d-%c %s\n",u,opl,val,opr,v);
/*
利用map的性质,没有插入的元素的第二个键值为0
*/
if(!ma[u]){//在城市中没有标记
ma[u]=len++;
//cout<<u<<endl;
}
if(!ma[v]){//在城市中没有标记
ma[v]=len++;
//cout<<v<<endl;
}
if(opl=='<'){
if(mapn[ma[v]][ma[u]]>val)
mapn[ma[v]][ma[u]]=val;
}
if(opr=='>'){
if(mapn[ma[u]][ma[v]]>val)
mapn[ma[u]][ma[v]]=val;
}
}//建图
//cout<<len<<endl;
//for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// cout<<mapn[i][j]<<" ";
// }
// cout<<endl;
//}
floyd();
cur=;
int lost=ma[city[]];
for(int i=;i<=c;i++){
cur+=mapn[lost][ma[city[i]]]+mapn[ma[city[i]]][lost];
//cout<<mapn[lost][ma[city[i]]]<<endl;
}
printf("%d. %d\n",Case++,cur);
}
return ;
}
Einbahnstrasse的更多相关文章
- HDU2923 Einbahnstrasse (Floyd)
Einbahnstrasse Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU - 2923 - Einbahnstrasse
题目: Einbahnstrasse Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Einbahnstrasse HDU2923
基础2923题 处理输入很麻烦 有可能一个城市有多辆破车要拖 应该严谨一点的 考虑所有情况 #include<bits/stdc++.h> using namespace std; ] ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- 【HDOJ图论题集】【转】
=============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- 转载 - 最短路&差分约束题集
出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★ ...
- 最短路&查分约束
[HDU] 1548 A strange lift 根蒂根基最短路(或bfs)★ 2544 最短路 根蒂根基最短路★ 3790 最短路径题目 根蒂根基最短路★ 2066 一小我的观光 根蒂根基最短路( ...
随机推荐
- Ensemble Learning: Bootstrap aggregating (Bagging) & Boosting & Stacked generalization (Stacking)
Booststrap aggregating (有些地方译作:引导聚集),也就是通常为大家所熟知的bagging.在维基上被定义为一种提升机器学习算法稳定性和准确性的元算法,常用于统计分类和回归中. ...
- java 读取properties文件总结
一.java读取properties文件总结 在java项目中,操作properties文件是经常要做的,因为很多的配置信息都会写在properties文件中,这里主要是总结使用getResource ...
- WPF控件自适应屏幕
如果说界面设计,那么自适应问题一定无法避免,今天就来分享一下,wpf如何实现自适应,先看一下效果:(文末添加源代码下载) 基本思路就是用 Grid 的网格,进行宽度的自动填充适应, 不过对于 ...
- java复习要点(一)------- java语言的特点、java的工作原理、配置环境变量、java命令的使用
一.java语言的特点: (1)简单并面向对象 (2)鲁棒并安全: java语言在编译及运行程序时,都要进行严格的检查,防止不匹配问题的发生.如果引用一个非法类型,或执行一个非法类型操作,java减肥 ...
- LPCTSTR LPCWSTR LPCSTR 含义
#ifdef UNICODE#define LPCTSTR LPCWSTR#else#define LPCTSTR LPCSTR#endif LPCTSTR A 32-bit pointer ...
- Problem 2062 Suneast & Yayamao 二进制(多重背包的理解基础)
Problem 2062 Suneast & Yayamao Accept: 143 Submit: 313T ...
- 约会安排HDU - 4553
寒假来了,又到了小明和女神们约会的季节. 小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复"呵呵",所以,小明的最爱就是和女神们约会.与此同时,也有很多基 ...
- java中属性,set get 以及如何学习类的一些用法
1,先来看一个例子 package com.tdq.java; public class Run { public static void main(String[]args){ Student st ...
- hadoop配置文件详解,安装及相关操作
一. Hadoop伪分布配置 1. 在conf/hadoop-env.sh文件中增加:export JAVA_HOME=/home/Java/jdk1.6 2. 在conf/core-s ...
- django使用xlwt导出excel文件
这里只是mark一下导出的方法,并没有做什么REST处理和异常处理. 维护统一的style样式,可以使导出的数据更加美观. def export_excel(request): # 设置HttpRes ...