HDU - 2923 - Einbahnstrasse
题目:
Einbahnstrasse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1548 Accepted Submission(s): 428
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.
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.
k . V
Where k is test case number (starting at 1,) is a space, and V is the result.
- #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的更多相关文章
- HDU 2923 Relocation(状压dp+01背包)
题目代号:HDU2923 题目链接:http://poj.org/problem?id=2923 Relocation Time Limit: 1000MS Memory Limit: 65536K ...
- hdu 2923 map+Floyd 拉破车
有向图 具体方向看箭头 从起点到指定城市拉破车,一个城市可能有多个破车,一次只能拉一辆破车 也就是到了指定地点后要回到起点 假如有100辆破车 但是只有一个城市有 就得在起点与这个城市间往返100次所 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
- 转载 - 最短路&差分约束题集
出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★ ...
- 最短路&查分约束
[HDU] 1548 A strange lift 根蒂根基最短路(或bfs)★ 2544 最短路 根蒂根基最短路★ 3790 最短路径题目 根蒂根基最短路★ 2066 一小我的观光 根蒂根基最短路( ...
- hdu 1596 find the safest road (最短路径)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- 【POJ 2449】 Remmarguts' Date
[题目链接] http://poj.org/problem?id=2449 [算法] A*(启发式搜索) 首先,求第k短路可以用优先队列BFS实现,当T第k次入队时,就求得了第k短路,但是,这种做法的 ...
- B1295 [SCOI2009]最长距离 最短路
就是一道最短路的裸题,直接跑spfa就行了.(spfa死了) 最后在答案处判断是否障碍物太多,然后就直接找最大值就行. (数据特别水,我错误算法60) 题干: Description windy有一块 ...
- 杂项:MIS(管理信息系统)
ylbtech-杂项:MIS(管理信息系统) 管理信息系统(Management Information System,简称MIS)是一个以人为主导,利用计算机硬件.软件.网络通信设备以及其他办公设备 ...
- 96.extjs 页面
1.登录js /** * @author sux * @desc 登录 */ Ext.onReady(function(){ Ext.QuickTips.init(); //错误信息显示必须 var ...
- Spark常见编程问题解决办法及优化
目录 1.数据倾斜 2.TopN 3.Join优化 预排序的join cross join 考虑Join顺序 4.根据HashMap.DF等数据集进行filter 5.Join去掉重复的列 6.展开N ...
- [Apple开发者帐户帮助]二、管理你的团队(1)邀请团队成员
组织可以选择向其开发团队添加其他人员.如果您已加入Apple开发者计划,您将在App Store Connect中管理团队成员.有关详细信息,请转到在App Store Connect帮助中添加用户. ...
- 【Codeforces】Codeforces Round #374 (Div. 2) -- C. Journey (DP)
C. Journey time limit per test3 seconds memory limit per test256 megabytes inputstandard input outpu ...
- pinpoint 磁盘不足的坑
观察 pinpoint hbase 数据存储目录default中各个表的大小 TraceV2 15G ApplicationTraceIndex 15G major_compact的操作目的 合并文件 ...
- rabbit channel参数
channel.exchangeDeclare() channel.ExchangeDeclare(string exchange: "cjlTest",string type: ...
- 小程序开发之搭建WebSocket的WSS环境(Apache+WorkerMan框架+PHP)
最近公司的一个IoT项目用到了小程序的WSS协议环境,现在把整个的搭建开发过程分享给大家. 这里我们用的是WorkerMan框架,服务器是CentOS,Web服务器是Apache,开发语言是PHP. ...