HDUOJ---2112HDU Today
HDU Today
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12147 Accepted Submission(s): 2851
这样住了一段时间,徐总对当地的交通还是不太了解。有时很郁闷,想去一个地方又不知道应该乘什么公交车,在什么地方转车,在什么地方下车(其实徐总自己有车,却一定要与民同乐,这就是徐总的性格)。
徐总经常会问蹩脚的英文问路:“Can you help me?”。看着他那迷茫而又无助的眼神,热心的你能帮帮他吗?
请帮助他用最短的时间到达目的地(假设每一路公交车都只在起点站和终点站停,而且随时都会开)。
第二行有徐总的所在地start,他的目的地end;
接着有n行,每行有站名s,站名e,以及从s到e的时间整数t(0<t<100)(每个地名是一个长度不超过30的字符串)。
note:一组数据中地名数不会超过150个。
如果N==-1,表示输入结束。
xiasha westlake
xiasha station 60
xiasha ShoppingCenterofHangZhou 30
station westlake 20
ShoppingCenterofHangZhou supermarket 10
xiasha supermarket 50
supermarket westlake 10
-1
Hint:
The best route is:
xiasha->ShoppingCenterofHangZhou->supermarket->westlake
虽然偶尔会迷路,但是因为有了你的帮助
**和**从此还是过上了幸福的生活。
――全剧终――
#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的更多相关文章
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- 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 ...
- 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 ...
- hdu-oj 1874 畅通工程续
最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...
- C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...
- C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...
- HDUOJ题目HTML的爬取
HDUOJ题目HTML的爬取 封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可. 其实没什么难度,先爬下来一个题目的 ...
- hduoj 1251 统计难题
http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hduoj 1286 找新朋友
http://acm.hdu.edu.cn/showproblem.php?pid=1286 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hduoj 1285 确定比赛名次
http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...
随机推荐
- Vmware esx/esxi Vlan三种配置模式(VST、EST和VGT)
在Vmware esx/esxi中使用虚拟Lan(Vlan)时,一般是指Vlan Trunk的使用,使用的Vlan配置还有其它三种类型: Virtual Switch Tagging(虚拟交换机标记, ...
- Objective-C:除数为0的情况下异常的处理(检测、抛出、捕捉、处理)
// DivTest.h // 异常的处理 // // Created by ma c on 15/8/11. // Copyright (c) 2015年. All rights reserved. ...
- 理清Processor, Processor Sockets, Processor Cores, Logical Processors, Hyperthreading这些概念吧
如果你只知道CPU这么一个概念,那么是无法理解CPU的拓扑的.事实上,在NUMA架构下,CPU的概念从大到小依次是:Node.Socket.Core.Logical Processor. 随着多核技术 ...
- Binary Tree Postorder Traversal leetcode java
题目: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bin ...
- Div+Css实现段落首行缩进两个字符(text-indent标签)
段落前面空两个字的距离,不要再使用空格了,用CSS实现段落首缩进两个字符.应该使用首行缩进text-indent.text-indent可以使得容器内首行缩进一定单位.比如中文段落一般每段前空两个汉字 ...
- 浏览WPF中内置颜色名对应的颜色
- eclipse全屏模式
- 【Javascript Demo】遮罩层和弹出层简单实现
最近纠结于遮罩层和弹出层的实现,终于搞定了个简单的版本.示例和代码如下,点击按钮可以看到效果: 1.示例: 2.代码: <!DOCTYPE html PUBLIC "-//W3C//D ...
- 使用mysql 统计函数 结果为null时返回值改为0
SELECT COALESCE(SUM(total),0) FROM test_table
- 微信小程序 - 各种示例
示例更新(后续持续更新): 最后一次更新:2018-11-7 小程序-地图显示(调用高德地图.腾讯App) - (2018-11-1) 小程序-上传图片(上传.预览.展示.删除) - (2018-11 ...