原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2722
分析:简单最短路,读入数据烦。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define maxn 450
#define inf 0xfffffff
using namespace std;
int blip[maxn];
int n,m;
bool vis[maxn];
struct edge
{
int to,w;
edge(int x,int y)
{
to=x;w=y;
}
};
vector<edge>e[maxn];
queue<int>q;
void spfa(const int s)
{
while(!q.empty())q.pop();
for(int i=;i<(n+)*(m+);i++)
{
vis[i]=false;
blip[i]=inf;
}
vis[s]=true;blip[s]=;
q.push(s);
while(!q.empty())
{
int u=q.front();q.pop();
for(int i=;i<e[u].size();i++)
{
if(blip[e[u][i].to]>blip[u]+e[u][i].w)
{
blip[e[u][i].to]=blip[u]+e[u][i].w;
if(!vis[e[u][i].to])
{
vis[e[u][i].to]=true;
q.push(e[u][i].to);
}
}
}
vis[u]=false;
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
if(n==||m==)break;
for(int i=;i<maxn;i++)e[i].clear();
for(int i=;i<=*n;i++)
{
int pp=m;if(i&)pp++;
for(int j=;j<pp;j++)
{
int v;char c;int tmp;
scanf("%d %c",&v,&c);
if(v!=)
{
if(c=='*'&&i%==)
{
tmp=i/*(m+)+j;
e[tmp].push_back(edge(tmp+,/v));
e[tmp+].push_back(edge(tmp,/v));
}
else if(c=='*'&&(i&))
{
tmp=i/*(m+)+j;
e[tmp].push_back(edge(tmp+m+,/v));
e[tmp+m+].push_back(edge(tmp,/v));
}
else if(c=='>')e[i/*(m+)+j].push_back(edge(i/*(m+)+j+,/v));
else if(c=='<')e[i/*(m+)+j+].push_back(edge(i/*(m+)+j,/v));
else if(c=='v')e[i/*(m+)+j].push_back(edge(i/*(m+)+j+m+,/v));
else if(c=='^')e[i/*(m+)+j+m+].push_back(edge(i/*(m+)+j,/v));
}
}
}
spfa();
if(blip[(n+)*(m+)-]==inf)cout<<"Holiday\n";
else printf("%d blips\n",blip[(n+)*(m+)-]);
}
return ;
}