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 ...
随机推荐
- Python Post img
from poster.encode import multipart_encode from poster.streaminghttp import register_openers import ...
- Android中怎样调用拨打电话?
Android系统原本就为手机设计,所以,在android系统中的不论什么App中,仅仅要愿意,拨打指定电话很方便. 核心就是使用Intent跳转,指定请求Action为Intent.ACTION_C ...
- [leetcode]Construct Binary Tree from Preorder and Inorder Traversal @ Python
原题地址:http://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 题意:根 ...
- Steps to configure a FileShare Quorum Witness for Windows Failover Cluster
Step 1: Step 2: Step 3: Step 4: You must use the wizard to create the file share. Step 5: to make su ...
- Template Method 模板方法 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- rcp(插件开发) The 'Eclipse-LazyStart' header is deprecated, use 'Bundle-ActivationPolicy'
'Eclipse-LazyStart' 这个规范在3.4 osgi 4.1 以后就不支持了 大家使用Bundle-ActivationPolicy: lazy 这个属性来实现插件的懒加载吧!
- kettle利用参数遍历执行指定目录下的所有对象
使用kettle设计ETL设计完成后,我们就需要按照我们业务的需要对我们设计好的ETL程序,ktr或者kjb进行调度,以实现定时定点的数据抽取,或者说句转换工作,我们如何实现调度呢? 场景:在/wor ...
- C#.NET常见问题(FAQ)-listView如何显示网格线
把GridLines设置为True 更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youku.com/acetaohai123 我的在线论坛: http:/ ...
- uva 11181 - Probability|Given(概率)
题目链接:uva 11181 - Probability|Given 题目大意:有n个人去超市买东西,给出r,每个人买东西的概率是p[i],当有r个人买东西的时候,第i个人恰好买东西的概率. 解题思路 ...
- 算法笔记_121:蓝桥杯第六届省赛(Java语言C组部分习题)试题解答
目录 1 隔行变色 2 立方尾不变 3 无穷分数 4 格子中输出 5 奇妙的数字 6 打印大X 前言:以下试题解答代码部分仅供参考,若有不当之处,还请路过的同学提醒一下~ 1 隔行变色 隔行变色 ...