hdu 2923 map+Floyd 拉破车
有向图 具体方向看箭头 从起点到指定城市拉破车,一个城市可能有多个破车,一次只能拉一辆破车 也就是到了指定地点后要回到起点
假如有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 拉破车的更多相关文章
- HDU - 2923 - Einbahnstrasse
题目: Einbahnstrasse Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 1217 (Floyd变形)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1217 Arbitrage (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- HDU 4034 Graph(Floyd变形——逆向判断)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...
- hdu 2112 HDU Today(map与dijkstra的结合使用)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 2923 Relocation(状压dp+01背包)
题目代号:HDU2923 题目链接:http://poj.org/problem?id=2923 Relocation Time Limit: 1000MS Memory Limit: 65536K ...
- HDU 2824 简单欧拉函数
1.HDU 2824 The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...
- hdu 1596(Floyd 变形)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...
- hdu 1869 (Floyd)
http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others) Memory ...
随机推荐
- 继承自NSObject的不常用又很有用的函数(1)
初始化阶段 —— load 和 initialize load函数 原型: +(void)load 当类被引用进程序的时候会执行这个函数. 在一个程序开始运行之前(在main函数开始执行之前),在库开 ...
- Strongly connected HDU - 4635(判断强连通图 缩点)
找出强联通块,计算每个连通块内的点数.将点数最少的那个连通块单独拿出来,其余的连通块合并成一个连通分量. 那么假设第一个连通块的 点数是 x 第二个连通块的点数是 y 一个强连通图(每两个点之间,至 ...
- CodeForces - 707C
C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 【刷题】BZOJ 2194 快速傅立叶之二
Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. a,b中的元素均为小于等于100的非 ...
- 【bzoj1044】木棍分割
Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍被分成了很多段,要求满足总长度最大的一段长 ...
- Oracle数据库--PL/SQL存储过程和函数的建立和调用
1.存储过程建立的格式: create or replace procedure My_Procedure is begin --执行部分(函数内容); end; / 例子:(以hr表为例) crea ...
- [IOI2018] werewolf 狼人
[IOI2018] werewolf 狼人 IOI2018题解 (其实原题强制在线,要用主席树) 代码: 注意: 1.下标从0~n-1 2.kruskal重构树开始有n个节点,tot从n开始,++to ...
- 浅谈使用NIO,AIO的感受
花了十多天的时间把原来的WEB服务由BIO(阻塞IO)模式改写成NIO(非阻塞IO)模式,然后在xp机子上用ab测试并发性能,确实提升了30%左右的并发性能,测试完成后,当时感觉还是挺满意的.几天前在 ...
- pyspider框架的599证书问题
使用PySpider 框架出现错误 HTTP 599: SSL certificate problem: unable to get local issuer certificate,如下 HTTP ...
- bzoj千题计划222:bzoj2329: [HNOI2011]括号修复(fhq treap)
http://www.lydsy.com/JudgeOnline/problem.php?id=2329 需要改变的括号序列一定长这样 :)))((( 最少改变次数= 多余的‘)’/2 [上取整] + ...