有向图 具体方向看箭头 从起点到指定城市拉破车,一个城市可能有多个破车,一次只能拉一辆破车 也就是到了指定地点后要回到起点

假如有100辆破车 但是只有一个城市有 就得在起点与这个城市间往返100次
所以要用s1记录

然后 貌似这题是有重边的....
sscanf(s4,"%d" ,&w) ; 这个是错的=.= 在这折腾了半天

Sample Input
4 2 5 //城市数 破车数 边数
NewTroy Midvale Metrodale //起点 + 有破车的城市
NewTroy <-20-> Midvale
Midvale --50-> Bakerline
NewTroy <-5-- Bakerline
Metrodale <-30-> NewTroy
Metrodale --5-> Bakerline
0 0 0

Sample Output
1. 80 //Case.  sum

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <algorithm>
# include <cmath>
# include <map>
# define LL long long
using namespace std ; const int MAXN = ;
const int INF = 0x3f3f3f3f;
int dis[MAXN][MAXN];
int n ;
map<string,int> mp ; void floyed()//节点从1~n编号
{
int i,j,k;
for(k=;k<=n;k++)
for(i=;i<=n;i++)
for(j=;j<=n;j++)
if(dis[i][k]+dis[k][j] < dis[i][j])
dis[i][j]=dis[i][k]+dis[k][j]; } int main()
{
// freopen("in.txt","r",stdin) ;
int m , c ;
int Case = ;
while (cin>>n>>c>>m)
{
if (n == && c == && m == )
break ;
Case++ ;
int i , j ;
for(i=;i<=n;i++)
for(j=;j<=n;j++)
{
if(i==j)dis[i][j]=;
else dis[i][j]=INF;
}
mp.clear() ;
string s1[] ,s2,s3;
int l = ;
for (i = ; i <= c ; i++) //起点+ 有破车的城市
{
cin>>s1[i] ;
if (!mp[s1[i]])
mp[s1[i]] = l++ ;
}
char s4[] ; int w ;
while(m--)
{
cin>>s2>>s4>>s3 ;
bool f1 = ;
bool f2 = ;
if (!mp[s2])
mp[s2] = l++ ;
if (!mp[s3])
mp[s3] = l++ ;
int len = strlen(s4) ;
if (s4[] == '<')
f1 = ;
if (s4[len-] == '>')
f2 = ;
sscanf(&s4[],"%d" ,&w) ;
if (f1 && w < dis[mp[s3]][mp[s2]])
dis[mp[s3]][mp[s2]] = w ;
if (f2 && w < dis[mp[s2]][mp[s3]])
dis[mp[s2]][mp[s3]] = w ;
}
floyed() ;
int sum = ;
for (i = ; i <= c ; i++)
{
sum += dis[mp[s1[]]][mp[s1[i]]] ;
sum += dis[mp[s1[i]]][mp[s1[]]] ;
}
cout<<Case<<". "<<sum<<endl ; }
return ;
}

hdu 2923 map+Floyd 拉破车的更多相关文章

  1. HDU - 2923 - Einbahnstrasse

    题目: Einbahnstrasse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. hdu 1217 (Floyd变形)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)   ...

  3. HDU 1217 Arbitrage (Floyd)

    Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...

  4. HDU 4034 Graph(Floyd变形——逆向判断)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...

  5. hdu 2112 HDU Today(map与dijkstra的结合使用)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

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

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

  7. HDU 2824 简单欧拉函数

    1.HDU 2824   The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...

  8. hdu 1596(Floyd 变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...

  9. hdu 1869 (Floyd)

    http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. Python【知识点】面试小点列表生成式小坑

    1.问题 有这么一个小面试题: 看下面代码请回答输出的结果是什么?为什么? result = [lambda x: x + i for i in range(10)] print(result[0]( ...

  2. StringUtils方法全集(转)

    JAVA对于字符串的操作真是太强大了!!! 在 commons-lang3-3.2.jar 包里 org.apache.commons.lang.StringUtils中方法的操作对象是java.la ...

  3. linux下转换windows文件格式为unix sed -i 's/\r//' <filename> 转化为unix格式

    sed -i 's/\r//' <filename> 转化为unix格式

  4. 【bzoj4537】 Hnoi2016—最小公倍数

    http://www.lydsy.com/JudgeOnline/problem.php?id=4537 (题目链接) 题意 给出一个${n}$个点${m}$条边的无向图,每条边有两个权值${a,b} ...

  5. 【转】在windows中使用Intellij Idea时选择自定义的64位JVM

    原文地址:https://www.iflym.com/index.php/code/201404190001.html 本文英文原文自:https://intellij-support.jetbrai ...

  6. 解题:HNOI 2013 Cards

    题面 除了不洗牌以外,每种洗牌方式的每个循环里的颜色必须一样,然后大力背包一下就好了.最后记得把不洗牌的方案也算进去 #include<cstdio> #include<cstrin ...

  7. StratifiedKFold与GridSearchCV版本前后使用方法

    首先在sklearn官网上你可以看到: 所以,旧版本import时: from sklearn.cross_validation import GridSearchCV 新版本import时: fro ...

  8. keystone v3.0与2.0的区别

    参看http://blog.chinaunix.net/uid-21335514-id-3497996.html

  9. C++外观模式和组合模式

    外观模式应该是用的很多的一种模式,特别是当一个系统很复杂时,系统提供给客户的是一个简单的对外接口,而把里面复杂的结构都封装了起来.客户只需使用这些简单接口就能使用这个系统,而不需要关注内部复杂的结构. ...

  10. 素数筛选法(prime seive)

    素数筛选法比较有名的,较常用的是Sieve of Eratosthenes,为古希腊数学家埃拉托色尼(Eratosthenes 274B.C.-194B.C.)提出的一种筛选法.详细步骤及图示讲解,还 ...