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 ...
随机推荐
- JAVA类变量(静态变量)
类变量也称为静态变量,在类中以static关键字声明,但必须在方法.构造方法和语句块之外. -无论一个类创建了多少个对象,类只拥有类变量的一份拷贝. -静态变量除了被声明为常量外很少使用.常量是指声明 ...
- BZOJ 2648 / 2716 K-D Tree 模板题
#include <cstdio> #include <cmath> #include <cstring> #include <algorithm> # ...
- 【BZOJ4444】国旗计划
Description 题目链接 Solution 磕了3个半小时没做出来的题,就是全场崩. 首先对于一个人的答案是很好求的,显然是选择左端点在此人区间中,右端点最远(最靠右)的人作为下一个接棒人.因 ...
- 解题:BZOJ 2989 数列
题面 学习二进制分组 题目本身可以看成二维平面上的问题,转成切比雪夫距离后就是矩形和了 二进制分组是将每个修改添加到末尾,然后从后往前二进制下进位合并,这样最多同时有$\log n$组,每个修改只会被 ...
- Hadoop生态圈-使用Kafka命令在Zookeeper中对应关系
Hadoop生态圈-使用Kafka命令在Zookeeper中对应关系 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.zookeeper保存kafka的目录 二.使用Ka ...
- np.random.rand均匀分布随机数和np.random.randn正态分布随机数函数使用方法
np.random.rand用法 觉得有用的话,欢迎一起讨论相互学习~Follow Me 生成特定形状下[0,1)下的均匀分布随机数 np.random.rand(a1,a2,a3...)生成形状为( ...
- Spark记录-官网学习配置篇(二)
### Spark SQL Running the SET -v command will show the entire list of the SQL configuration. #scala/ ...
- Comparing Differently Trained Models
Comparing Differently Trained Models At the end of the previous post, we mentioned that the solution ...
- 略显犀利的 js 判断闰年
/** * 判断闰年函数 * @param {number} year 要判断的年份 * @return {bool} 返回布尔值 * * 其实只要满足下面几个条件即可. * 1.普通年能被4整除且不 ...
- spring Mvc 执行原理 及 xml注解配置说明 (六)
Spring MVC 执行原理 在 Spring Mvc 访问过程里,每个请求都首先经过 许多的过滤器,经 DispatcherServlet 处理; 一个Spring MVC工程里,可以配置多个的 ...