HDU Today

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12147    Accepted Submission(s): 2851

Problem Description
经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强。这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬浦镇陶姚村买了个房子,开始安度晚年了。
这样住了一段时间,徐总对当地的交通还是不太了解。有时很郁闷,想去一个地方又不知道应该乘什么公交车,在什么地方转车,在什么地方下车(其实徐总自己有车,却一定要与民同乐,这就是徐总的性格)。
徐总经常会问蹩脚的英文问路:“Can you help me?”。看着他那迷茫而又无助的眼神,热心的你能帮帮他吗?
请帮助他用最短的时间到达目的地(假设每一路公交车都只在起点站和终点站停,而且随时都会开)。
 
Input
输入数据有多组,每组的第一行是公交车的总数N(0<=N<=10000);
第二行有徐总的所在地start,他的目的地end;
接着有n行,每行有站名s,站名e,以及从s到e的时间整数t(0<t<100)(每个地名是一个长度不超过30的字符串)。
note:一组数据中地名数不会超过150个。
如果N==-1,表示输入结束。
 
Output
如果徐总能到达目的地,输出最短的时间;否则,输出“-1”。
 
Sample Input
6
xiasha westlake
xiasha station 60
xiasha ShoppingCenterofHangZhou 30
station westlake 20
ShoppingCenterofHangZhou supermarket 10
xiasha supermarket 50
supermarket westlake 10
-1
 
Sample Output
50

Hint:
The best route is:
xiasha->ShoppingCenterofHangZhou->supermarket->westlake

虽然偶尔会迷路,但是因为有了你的帮助
**和**从此还是过上了幸福的生活。

――全剧终――

 
Author
lgx
 
Source
 
Recommend
 
这道题是看了别人的提示才AC的,这里如果起点和终点没有线路那就输出-1。、、、、我只想说魂淡呀..
 #pragma warning (disable :4786)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<string>
using namespace std; const int inf=0x3f3f3f3f;
const int tol=;
int path[tol],lowc[tol];
int sta[tol][tol];
map<string,int>sav;
void Dijkstra( int n,int beg )
{
int i,j,minc;
int vis[tol]={};
vis[beg]=;
for(i=;i<n;i++)
{
lowc[i]=sta[beg][i];
path[i]=beg;
}
lowc[beg]=;
path[beg]=-;
int pre=beg;
for(i= ; i<n ;i++)
{
minc=inf;
for(j=;j<n;j++)
{
if(vis[j]==&&lowc[pre]+sta[pre][j]<lowc[j])
{
lowc[j]=lowc[pre]+sta[pre][j];
path[j]=pre;
}
}
for(j=;j<n;j++)
{
if(vis[j]==&&lowc[j]<minc)
{
minc=lowc[j];
pre=j;
}
}
vis[pre]=;
}
} int main( void )
{
int t,e,cc,i,j;
string str,en;
string aa,bb;
while(cin>>t,t!=-)
{
cin>>str>>en;
e=;
for(i=;i<tol;i++)
{
for(j=;j<tol;j++)
sta[i][j]=inf;
}
while(t--)
{
cin>>aa>>bb>>cc;
if(sav[aa]==) sav[aa]=e++;
if(sav[bb]==) sav[bb]=e++;
if(sta[sav[aa]-][sav[bb]-]>cc)
sta[sav[aa]-][sav[bb]-]=sta[sav[bb]-][sav[aa]-]=cc;
}
/* map<string,int>::iterator it;
for(it=sav.begin();it!=sav.end();it++)
{
cout<<it->first<<endl;
}*/
sta[sav[str]-][]=sta[][sav[str]-]=; //扩充图
sta[sav[en]-][e-]=sta[e-][sav[en]-]=;
sav.clear();
Dijkstra(e,);
if(lowc[e-]==inf) cout<<-<<endl;
else
cout<<lowc[e-]<<endl;
}
return ;}

HDUOJ---2112HDU Today的更多相关文章

  1. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  2. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  3. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  4. hdu-oj 1874 畅通工程续

    最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...

  5. C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...

  6. C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...

  7. HDUOJ题目HTML的爬取

    HDUOJ题目HTML的爬取 封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可. 其实没什么难度,先爬下来一个题目的 ...

  8. hduoj 1251 统计难题

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  9. hduoj 1286 找新朋友

    http://acm.hdu.edu.cn/showproblem.php?pid=1286 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  10. hduoj 1285 确定比赛名次

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...

随机推荐

  1. 《阿里巴巴JAVA开发手册》里面写超过三张表禁止join这是为什么?

    分库分页.应用里做join 多表join性能很差 参考: 1.https://www.zhihu.com/question/56236190

  2. BZOJ 4145 [AMPPZ2014] The Prices 解题报告

    感觉也是一个小清新题.. 我们考虑设立状态 $Dp[i][s]$ 表示考虑了前 $i$ 个商店后,购买状态为 $s$ 的最小花费. 转移的话就枚举每个商店 $i$,首先令: $$Dp[i][s] = ...

  3. Binary Tree Postorder Traversal leetcode java

    题目: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bin ...

  4. 用js做一个简单的留言板效果

    html部分: 1: <!DOCTYPE> 2: <html lang="zh-en"> 3: <head> 4: <title>j ...

  5. 再谈javascript图片预加载技术

    图片预加载技术的典型应用: 如lightbox方式展现照片,无疑需要提前获得大图的尺寸,这样才能居中定位,由于javascript无法获取img文件头数据,必须等待其加载完毕后才能获取真实的大小然后展 ...

  6. [Tools] Target specific browsers with babel-preset-env and the babel pollyfill (browserslist)

    Converting all of our modern JavaScript into ES5 compatible syntax is a great way to use modern feat ...

  7. 关于bootstrap-datetimepicker.js不支持IE8的解决办法

    if (!Array.prototype.indexOf) Array.prototype.indexOf = function (elt /*, from*/) { var len = this.l ...

  8. 【Window OS】”对于目标文件系统,文件XXXXX过大“导致无法进行文件操作的解决方法

    问题原因:这是目标文件系统不支持这么大的文件的操作问题.例如:目标文件系统的格式是FAT32,FAT32最大支持4G,如果你要进行发送或粘贴4G以上的文件就会出现这个问题. 解决办法:把目标文件系统的 ...

  9. MVC4.0网站发布

    一.VS2010下MVC4.0项目的发布 首先,生成网站发布文件. 第一步,"右击"要发布的MVC4.0项目,选择"发布(B)..."选项,如图: 第二步,在& ...

  10. Hibernate(九)HQL查询

    一.Hibernate提供的查询方式 OID查询方式:主键查询.通过get()或者load()方法加载指定OID的对象查询结果为一个 HQL查询方式:通过Query接口使用HQL语言进行查询 QBC查 ...