最短路,建图太麻烦,略过……

#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的更多相关文章

  1. POJ 3653 &amp; ZOJ 2935 &amp; HDU 2722 Here We Go(relians) Again(最短路dijstra)

    题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...

  2. HDU 2722 Here We Go(relians) Again (spfa)

    Here We Go(relians) Again Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/ ...

  3. 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 ...

  4. HDU 2722 Here We Go(relians) Again (最短路)

    题目链接 Problem Description The Gorelians are a warlike race that travel the universe conquering new wo ...

  5. 【HDOJ】2722 Here We Go(relians) Again

    根据矩阵建图,然后求最短路径. #include <cstdio> #include <cstring> #include <cstdlib> #define L ...

  6. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  7. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  8. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

随机推荐

  1. SGU 187.Twist and whirl - want to cheat( splay )

    维护一个支持翻转次数M的长度N的序列..最后输出序列.1<=N<=130000, 1<=M<=2000 splay裸题... ------------------------- ...

  2. BZOJ 2946: [Poi2000]公共串( 后缀自动机 )

    一个串建后缀自动机, 其他串在上面跑, 然后用当前串跑的去更新全部 ------------------------------------------------------------------ ...

  3. Spring学习之Jar包功能介绍(转)

    spring.jar 是包含有完整发布模块的单个jar 包.但是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2. ...

  4. 四轴飞行器1.2.2 RT-Thread 串口

    四轴飞行器1.2.2 RT-Thread 串口        本来是打算说根据RT-Thread的设备管理提供的驱动接口些串口驱动的,但是仔细一看,我去,串口驱动写好了,只需要调用就可以了.下面我们说 ...

  5. ora-01653: unable to extend table sys.aud$ by 8192 in tablespac system[转载]

    在用sqlplus user/password@truth登录数据库时报如下错误:ORA-00604: error occurred at recursive SQL level 1ORA-01653 ...

  6. C++中类成员函数作为回调函数

    注:与tr1::function对象结合使用,能获得更好的效果,详情见http://blog.csdn.net/this_capslock/article/details/38564719 回调函数是 ...

  7. [android]Gradle: 执行失败的任务 ': processDebugManifest'

    发现这一问题的解决方案: gradle 组装-信息确实给了我提示清单有不同版本的 SDK 并不能合并. 编辑我的清单和 build.gradle 文件和再工作的一切所需. 要弄清楚你需要编辑 uses ...

  8. CCNA实验(7) -- NAT

    1.静态NAT2.动态NAT3.复用内部全局地址的NAT(PAT) enableconf tno ip do loenable pass ciscoline con 0logg syncexec-t ...

  9. andrewchilds/jQuery.DomOutline

    andrewchilds/jQuery.DomOutline DOM - 使用Javascript:让用户选择一个类似Firebug的HTML元素? -

  10. 动态调用python类和函数

    类 class test1(object): def __init__(self): print "i am test1" class test2(object): def __i ...