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 ...
随机推荐
- select实现选中跳转
select选择后直接跳转到其他网站的三种方式 第一种: ************************** <html> <head> <meta http- ...
- PowerBuilder预防数据库死锁相关处理
实际业务中碰到了PB开发的业务系统造成的数据死锁情况,整理了一些PB关于数据库死锁的一些处理. PB死锁相关 1. 即时的commit和rollback 不同数据库的锁机制各不相同,但对应用程序来说, ...
- [Puzzle] 蚂蚁路线碰撞问题
有这么一道题目, 看下面的图, 假设有一条直线, 每个叉叉上有一只蚂蚁, 它们会随机选择一个方向, 向前或者向后移动, 每次走一格, 前进中当两只蚂蚁相遇, 它们会掉头, 问: 全部蚂蚁都走出去的最长 ...
- 《Effective C++》Item2:尽量以const,enum,inline替换#define
1. 宏定义 #define ASPECT_RATIO 1.653 该宏定义ASPECT_RATIO也许从来没有被编译器看到,也许在编译器开始处理源码之前就已经被预处理器替换了.所以记号名称ASPEC ...
- C# 后台调用前台JS
1.需要添加微软的类库 Interop.MSScriptControl.dll 2. var path = Path.GetFullPath("../../javascript/youzi ...
- ActiveMQ的入门demo
步骤: 1 :下载ActiveMQ 官网:http://activemq.apache.org/ 2 :解压AcitveMQ, 根据自己的操作系统选择运行win64或者win32下的activemq. ...
- 转: when.js原理和核心实现
这篇文章可以看作是屈屈同学关于when.js的文章<异步编程:When.js快速上手>的续篇. 屈屈的文章中详细介绍了when.js,在这里关于when.js的使用我就不多复述了,大家可以 ...
- Javascript 风格向导
序 大部分针对Javascript最合理的方法归纳. 类型 • 原始类型:我们可以直接使用值. ο string ο number ο boolean ο null ο undefined ...
- 用NDKr9编译最新ffmpeg2.0.1到android平台
原文来自http://www.mingjianhua.com 本文参照 http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/ 在linux下的 ...
- appledoc:Objective-C注释文档生成工具
appledoc是帮助Objective-C开发者从特殊格式的源代码注释中生成类似apple资源代码帮助文档的命令行工具. 安装和使用都非常简单: 安装 git clone git://github. ...