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 ...
随机推荐
- VBA 简单调试
在中断模式下(ctrl+Break键),可以做: 1.执行 工具----选项----编辑器----勾选“自动显示数据提示” 则当用鼠标悬停在变量或表达式上时,会出现提示窗口,显示其名称和值! 2 ...
- MATLAB一句总结
MATLAB使用过程中的一些小总结: 1.sqrt函数的输入参数应为double类型: 2.im2bw把图像转换为二值图像: 3.double类型的图片必须转换为uint8类型后才能用imshow显示 ...
- sql大数据量查询的优化技巧
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...
- js添加删除元素
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- CM 0313 Review
中午无聊看了贴吧,看到有人截图说CM有爱的故事.看到SE03CH13,觉得图有点印象,似乎我很是记得这一集.于是刚才看了一下,嗯,果然记得.是我头一次翻译美剧的时候,7年前. 剧情还可以吧,剧中的Ji ...
- Problem B: 最少步数
DescriptionA friend of you is doing research on theTraveling Knight Problem (TKP) where you are to f ...
- textarea中的空格与换行
当在一个textarea标签中键入一个回车时,实际上会插入2个符号:\n\r在javascript里, line breaks用\n表示when you pull text into Javascri ...
- 简谈python反射
写出一个简单类:import sysclass webserver(object): def __init__(self,host,post): self.host = host self.post ...
- C 查找子字符串
自己用 C 写的一个查找子字符串的函数 int findstr(char *str,char *substr) //C实现 find{ if(NULL == str || NULL== substr) ...
- Ceph相关博客、网站(256篇OpenStack博客)
官网文档: http://docs.ceph.com/docs/master/cephfs/ http://docs.ceph.com/docs/master/cephfs/createfs/ ( ...