HDU 2722 Here We Go(relians) Again
最短路,建图太麻烦,略过……
#include <cstdio>
#include <cstring>
#include <queue>
const int INF=9999999;
using namespace std;
struct node{
int v,i;
node(int a,int b){v=a,i=b;}
bool operator <(const node& a)const{return v>a.v;}
};
int n,m,map[500][500];
int done[500],d[500];
int dij(){
priority_queue q;
memset(done,0,sizeof done);
for(int i=1;i<=(n+1)*(m+1);i++)d[i]=INF;
d[1]=0;
q.push(node(d[1],1));
while(!q.empty()){
node nd=q.top();q.pop();
int u=nd.i;
if(done[u])continue;
done[u]=1;
for(int i=1;i<=(n+1)*(m+1);i++){
if(d[i]>d[u]+map[u][i]){
d[i]=d[u]+map[u][i];
q.push(node(d[i],i));
}
}
}
if(d[(n+1)*(m+1)]==INF)return -1;
else return d[(n+1)*(m+1)];
}
int main(){
char s[3];int v;
while(scanf("%d%d",&n,&m),n||m){
for(int i=1;i<=(n+1)*(m+1);i++)for(int j=1;j<=(n+1)*(m+1);j++)map[i][j]=INF;
int n1,n2;
for(int i=1;i<=2*n+1;i++){
if(i%2==1){
for(int j=1;j<=m;j++){
n1=(i/2)*(m+1)+j,n2=n1+1;
scanf("%d%s",&v,s);
if(v==0)continue;
if(s[0]=='*')map[n1][n2]=map[n2][n1]=2520/v;
else if(s[0]=='<')map[n2][n1]=2520/v;
else if(s[0]=='>')map[n1][n2]=2520/v;
}
}else{
for(int j=1;j<=m+1;j++){
n1=(i/2-1)*(m+1)+j,n2=n1+m+1;
scanf("%d%s",&v,s);
if(v==0)continue;
if(s[0]=='*')map[n1][n2]=map[n2][n1]=2520/v;
else if(s[0]=='v')map[n1][n2]=2520/v;
else if(s[0]=='^')map[n2][n1]=2520/v;
}
}
}
int r=dij();
if(r==-1)printf("Holiday\n");
else printf("%d blips\n",r);
}
return 0;
}
HDU 2722 Here We Go(relians) Again的更多相关文章
- POJ 3653 & ZOJ 2935 & HDU 2722 Here We Go(relians) Again(最短路dijstra)
题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...
- HDU 2722 Here We Go(relians) Again (spfa)
Here We Go(relians) Again Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/ ...
- hdu 2722 Here We Go(relians) Again (最短路径)
Here We Go(relians) Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- HDU 2722 Here We Go(relians) Again (最短路)
题目链接 Problem Description The Gorelians are a warlike race that travel the universe conquering new wo ...
- 【HDOJ】2722 Here We Go(relians) Again
根据矩阵建图,然后求最短路径. #include <cstdio> #include <cstring> #include <cstdlib> #define L ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
随机推荐
- WPF利用依赖属性和命令编写自定义控件
以实例讲解(大部分讲解在代码中) 1,新建一个WPF项目,添加一个用户控件之后在用户控件里面添加几个控件用作测试, <UserControl x:Class="SelfControlD ...
- HOJ1014
Niven Numbers My Tags (Edit) Source : Unknown Time limit : 1 sec Memory limit : 32 M Submitt ...
- nodejs取得mac地址
1.背景 使用nodejs取得客户端电脑的mac地址作为唯一的标识,但如何使用getmac模块, 本文结合网上资料和实践,总结如下: 2.需要的moduel ...
- .Net页面缓存OutPutCachexian详解
一 它在Web.Config中的位置 <system.web> <!--页面缓存--> <caching> <outputCacheSettings> ...
- 简单使用 PHP Phar 打包php代码 笔记
Phar简介:Phar 归档的概念来自 Java™ 技术的 JAR 归档,它允许使用单个文件打包应用程序,这个文件中包含运行应用程序所需的所有东西.该文件不同于单个可执行文件,后者通常由编程语言生成, ...
- 再探Delphi2010 Class的构造和析构顺序
发了上一篇博客.盒子上有朋友认为Class的构造和析构延迟加载.是在Unit的初始化后调用的Class的构造.在Unit的反初始化前调用的Class的析构函数. 为了证明一下我又做了个试验 unit ...
- POJ 1556 The Doors(计算几何+最短路)
这题就是,处理出没两个点.假设能够到达,就连一条边,推断可不能够到达,利用线段相交去推断就可以.最后求个最短路就可以 代码: #include <cstdio> #include < ...
- HDU1046:Gridland
Problem Description For years, computer scientists have been trying to find efficient solutions to d ...
- VIM在文件夹中查找
在vim中提供2中方法来在其他文件或者文件夹中搜索字符串,第一种是vimgrep还有一种是grep. 如果只是在当前打开的文件中查找字符串的,使用 :? 后面加上想要搜索的字符串就可以. 这里要解决的 ...
- WCF 出现无法理解Soap Action问题?
在使用wcf部署到asp.net上时,遇到了,“无法理解soap Action 问题,”最简单的解决办法是更换NET framwork 高本版的框架. 不过不更换net framwork 框架,能否解 ...