HDU 2122 HDU Today【Floyd】
题意:给出n条路,起点和终点,问最短距离
用map处理一下地名,再用floyd
可是不懂的是:为什么INF定义成0x7fffffff就输出一堆奇怪的东西,改成100000000就可以了
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
const int INF = ;
const int maxn=;
map<string,int> mp;
int d[maxn][maxn]; int main(){
int n,i,j,k,w;
string st,en,s1,s2;
while(scanf("%d",&n)!=EOF&&(n!=-)){
mp.clear();
int cnt=; for(i=;i<maxn;i++){
for(j=;j<maxn;j++){
if(i==j) d[i][j]=;
else d[i][j]=INF;
}
} cin>>st>>en;
if(!mp[st]) mp[st]=cnt++;
if(!mp[en]) mp[en]=cnt++; for(i=;i<n;i++){
cin>>s1>>s2>>w;
if(!mp[s1]) mp[s1]=cnt++;
if(!mp[s2]) mp[s2]=cnt++; if(d[mp[s1]][mp[s2]]>w) d[mp[s1]][mp[s2]]=d[mp[s2]][mp[s1]]=w;
} for(k=;k<cnt;k++)
for(i=;i<cnt;i++)
for(j=;j<cnt;j++)
d[i][j]=min(d[i][j],d[i][k]+d[k][j]); if(d[mp[st]][mp[en]]==INF) printf("-1\n");
else printf("%d\n",d[mp[st]][mp[en]]);
}
return ;
}
HDU 2122 HDU Today【Floyd】的更多相关文章
- HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Thickest Burger Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))
Four Operations Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)
Football Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- HDU 3916 Sequence Decomposition 【贪心】
这道题目的题意就是使用题目中所给的Gate 函数,模拟出输入的结果 当然我们分析的时候可以倒着来,就是拿输入去减 每次Gate 函数都会有一个有效范围 这道题目求的就是,找出一种模拟方法,使得最小的有 ...
- BZOJ1599 find the mincost route 【floyd】
题目链接 BZOJ1599 题解 最小环模板?周末了养生一下[逃] 解释一下原理 \(floyd\)算法每一轮求出以\([1,k]\)为中介点的最短路 我们对于一个环,考虑环上编号最大的点,在\(k\ ...
- 【Floyd】珍珠
[题目描述] 有n颗形状和大小都一致的珍珠,它们的重量都不相同.n为整数,所有的珍珠从1到n编号.你的任务是发现哪颗珍珠的重量刚好处于正中间,即在所有珍珠的重量中,该珍珠的重量列(n+1)/2位.下面 ...
- UESTC 30 &&HDU 2544最短路【Floyd求解裸题】
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 1869 六度分离【floyd】
题意:给出n个人,m个关系,问是否满足任意两个人之间的距离通过6个人就可以连接 用floyd就可以了,注意距离是大于7 #include<iostream> #include<cst ...
随机推荐
- Stacked injection--堆叠注入--堆查询注入
Stacked injection--堆叠注入--堆查询注入 原文地址;http://www.sqlinjection.net/stacked-queries/ 本篇属于集合原作者的思路和个人想法 ...
- Ruby中的Profiling工具
看看如何调试Ruby的性能问题 李哲 - APRIL 08, 2015 Ruby内置的profiler 内置的profiler实现的很简单,在ruby2.2中只有150行代码,大家可以看看它的实现pr ...
- mvc5 知识点01
1.ViewBag 动态数据类型,也就是说可以随便指定属性,前后台传值很是有用 2.Layout 属性,定义模版,模版中一般用@RenderBody() 做占位符,用于放置子页面内容 3.@model ...
- House Robber II
https://leetcode.com/problems/house-robber-ii/ Note: This is an extension of House Robber. After rob ...
- UVA 10673 扩展欧几里得
题意:给出x 和k,求解p和q使得等式x = p[x / k] + q [ x / k], 两个[x / k]分别为向下取整和向上取整 题解:扩展欧几里得 //meek///#include<b ...
- 记一段使用node对mysql数据库做处理
所用到的存储过程如下: temp_get_userCount: BEGIN #Routine body goes here... SELECT COUNT(id) as num FROM tbl_us ...
- Java-在线聊天系统-非线程
一.概述 1.目标:建立基于tcp协议的聊天系统 2.思路:用java socket编程 二.代码 1.ChatServer.java import java.io.DataInputStream; ...
- VCC、VDD、VEE、VSS等有关电源标注的区别
Almost all integrated circuits (ICs) have at least two pins which connect to the power rails of the ...
- 编写基于outlook显示的html邮件需要注意的问题
outlook对于html的支持是有限制的,在编写这些html的时候注意遵循以下规则: Never use colspans or rowspans. Always set correct dimen ...
- Android开发:彻底更改工程名
对于已经建立的工程,如果发现原来的工程名不合适,此时若想彻底更改工程名,需要三个步骤: 1.更改工程名 选中工程名,右键-->Refactor-->Rename. 2.更改src文件下包名 ...