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. 如何判断某版本的.NET Framework是否安装

    1..NET Framework .NET Framework2.0    键:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\N ...

  2. 深度学习阅读列表 Deep Learning Reading List

    Reading List List of reading lists and survey papers: Books Deep Learning, Yoshua Bengio, Ian Goodfe ...

  3. 2、COCOS2D-X内存管理机制

    在C++中.动态内存分配是一把双刃剑,一方面,直接訪问内存地址提高了应用程序的性能,与使用内存的灵活性.还有一方面.因为程序没有正确地分配与释放造成的比如野指针,反复释放,内存泄漏等问题又严重影响着应 ...

  4. [20] 鼓状物(Drum)图形的生成算法

    顶点数据的生成 bool YfBuildDrumVertices ( Yreal radius, Yreal assistRadius, Yuint slices, Yuint stacks, YeO ...

  5. sql server 将字符串分割成表函数 strsplitetotable

    在sql server里,调用存储过程时,经常需要将数据拼成字符串做为参数调用存储过程,而在储存过程中分割字符串虽然简单但麻烦,封装了该函数,可以将拼串分割成内存表返回,方便使用,返回的表字段从a,b ...

  6. WF4.0(2)----设计工作流

    自从做了程序员,发现自己长胖了,而且自己的身体抵抗力也出了问题,最近身体不适,公司工作任务最近也很赶,上次写了WF4.0的简介,这次就工作中工作流设计的几种方式稍微总结一下.设计工作流包括四种方式:流 ...

  7. RV 多样式 MultiType 聊天界面 消息类型 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. vue路由使用踩坑点:当动态路由再使用路由name去匹配跳转时总是跳转到根路由的问题

    闲话少说,直接问题: 之前我的路由时这么写的 { path:'/serverInfo/:id', name:'serverInfo', component:() => import('@/vie ...

  9. [Functional Programming] mapReduce over Async operations with first success prediction (fromNode, alt, mapReduce, maybeToAsync)

    Let's say we are going to read some files, return the first file which pass the prediction method, t ...

  10. Jmeter+Ant+Jenkins搭建持续集成的接口测试框架

    https://my.oschina.net/hellotest/blog/516079 摘要: 一个系统通常有多个接口,软件的生命周期中,我们会不断的去优化老的接口和开发新的接口,那么在这个过程中, ...