Here We Go(relians) Again

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 1   Accepted Submission(s) : 1

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

The Gorelians are a warlike race that travel the universe conquering new worlds as a form of recreation. Given their violent, fun-loving nature, keeping their leaders alive is of serious concern. Part of the Gorelian security plan involves changing the traffic patterns of their cities on a daily basis, and routing all Gorelian Government Officials to the Government Building by the fastest possible route.

Fortunately for the Gorelian Minister of Traffic (that would be you), all Gorelian cities are laid out as a rectangular grid of blocks, where each block is a square measuring 2520 rels per side (a rel is the Gorelian Official Unit of Distance). The speed limit between two adjacent intersections is always constant, and may range from 1 to 9 rels per blip (a blip, of course, being the Gorelian Official Unit of Time). Since Gorelians have outlawed decimal numbers as unholy (hey, if you're the dominant force in the known universe, you can outlaw whatever you want), speed limits are always integer values. This explains why Gorelian blocks are precisely 2520 rels in length: 2520 is the least common multiple of the integers 1 through 9. Thus, the time required to travel between two adjacent intersections is always an integer number of blips.

In all Gorelian cities, Government Housing is always at the northwest corner of the city, while the Government Building is always at the southeast corner. Streets between intersections might be one-way or two-way, or possibly even closed for repair (all this tinkering with traffic patterns causes a lot of accidents). Your job, given the details of speed limits, street directions, and street closures for a Gorelian city, is to determine the fastest route from Government Housing to the Government Building. (It is possible, due to street directions and closures, that no route exists, in which case a Gorelian Official Temporary Holiday is declared, and the Gorelian Officials take the day off.)

The picture above shows a Gorelian City marked with speed limits, one way streets, and one closed street. It is assumed that streets are always traveled at the exact posted speed limit, and that turning a corner takes zero time. Under these conditions, you should be able to determine that the fastest route from Government Housing to the Government Building in this city is 1715 blips. And if the next day, the only change is that the closed road is opened to two way traffic at 9 rels per blip, the fastest route becomes 1295 blips. On the other hand, suppose the three one-way streets are switched from southbound to northbound (with the closed road remaining closed). In that case, no route would be possible and the day would be declared a holiday.

Input

The input consists of a set of cities for which you must find a fastest route if one exists. The first line of an input case contains two integers, which are the vertical and horizontal number of city blocks, respectively. The smallest city is a single block, or 1 by 1, and the largest city is 20 by 20 blocks. The remainder of the input specifies speed limits and traffic directions for streets between intersections, one row of street segments at a time. The first line of the input (after the dimensions line) contains the data for the northernmost east-west street segments. The next line contains the data for the northernmost row of north-south street segments. Then the next row of east-west streets, then north-south streets, and so on, until the southernmost row of east-west streets. Speed limits and directions of travel are specified in order from west to east, and each consists of an integer from 0 to 9 indicating speed limit, and a symbol indicating which direction traffic may flow. A zero speed limit means the road is closed. All digits and symbols are delimited by a single space. For east-west streets, the symbol will be an asterisk '*' which indicates travel is allowed in both directions, a less-than symbol '<' which indicates travel is allowed only in an east-to-west direction, or a greater-than symbol '>' which indicates travel is allowed only in a west-to-east direction. For north-south streets, an asterisk again indicates travel is allowed in either direction, a lowercase "vee" character 'v' indicates travel is allowed only in a north-to-south directions, and a caret symbol '^' indicates travel is allowed only in a south-to-north direction. A zero speed, indicating a closed road, is always followed by an asterisk. Input cities continue in this manner until a value of zero is specified for both the vertical and horizontal dimensions.

Output

For each input scenario, output a line specifying the integer number of blips of the shortest route, a space, and then the word "blips". For scenarios which have no route, output a line with the word "Holiday".

Sample Input

2 2
9 * 9 *
6 v 0 * 8 v
3 * 7 *
3 * 6 v 3 *
4 * 8 *
2 2
9 * 9 *
6 v 9 * 8 v
3 * 7 *
3 * 6 v 3 *
4 * 8 *
2 2
9 * 9 *
6 ^ 0 * 8 ^
3 * 7 *
3 * 6 ^ 3 *
4 * 8 *
0 0

Sample Output

1715 blips
1295 blips
Holiday
/*
这题题目很长,关键在于输入,一条一条输入
‘*’:表示双向
‘>’:表示只能从左向右
‘<’:表示只能从右向左
‘^’:表示只能从下往上
‘v’:表示只能从上往下
如果一条路上的规定速度为0,表示不通
如果不能从左上到右下则输出“Holiday”
否则输出最短的时间
*/ #include <iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
const int inf=0x7fffffff;
struct node
{
int num,v;
node(int a,int b){num=a; v=b;}
};
vector<node> s[*];
int n,m;
bool vis[*];
int dis[*];
void spfa()
{
for(int i=;i<=(n+)*(m+);i++)dis[i]=inf,vis[i]=;
queue<int> Q;
dis[]=;
vis[]=;
Q.push();
while(!Q.empty())
{
int u=Q.front();
Q.pop();
vis[u]=;
for(int i=;i<s[u].size();i++)
{
if(dis[s[u][i].num]<=dis[u]+/s[u][i].v) continue;
dis[s[u][i].num]=dis[u]+/s[u][i].v;
if(!vis[s[u][i].num])
{
vis[s[u][i].num]=;
Q.push(s[u][i].num);
}
}
}
}
void read()
{
int x;
char ch[];
for(int i=;i<=(n+)*(m+);i++) s[i].clear();
for(int i=;i<=m;i++) //先处理第一行
{
scanf("%d",&x);
scanf("%s",&ch);
if(x==) continue;
if (ch[]=='*')
{
s[i].push_back(node(i+,x));
s[i+].push_back(node(i,x));
}
if (ch[]=='>')s[i].push_back(node(i+,x));
if (ch[]=='<')s[i+].push_back(node(i,x));
} for(int i=;i<=n;i++)
{
for(int j=;j<=(m+);j++)
{
scanf("%d",&x);
scanf("%s",&ch);
if (x==) continue;
int p=(i-)*(m+)+j;
int q=i*(m+)+j;
if (ch[]=='*')
{
s[p].push_back(node(q,x));
s[q].push_back(node(p,x));
}
if (ch[]=='^') s[q].push_back(node(p,x));
if (ch[]=='v') s[p].push_back(node(q,x));
} for(int j=;j<=m;j++)
{
scanf("%d",&x);
scanf("%s",&ch);
if (x==) continue;
int p=i*(m+)+j;
int q=i*(m+)+j+;
if (ch[]=='*')
{
s[p].push_back(node(q,x));
s[q].push_back(node(p,x));
}
if (ch[]=='<') s[q].push_back(node(p,x));
if (ch[]=='>') s[p].push_back(node(q,x));
} }
return;
}
int main()
{
while(scanf("%d%d",&n,&m))
{
if (n== && m==) break;
read();
spfa();
if (dis[(n+)*(m+)]==inf) printf("Holiday\n");
else printf("%d blips\n",dis[(n+)*(m+)]);
}
return ;
}

HDU 2722 Here We Go(relians) Again (spfa)的更多相关文章

  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. 模板C++ 03图论算法 1最短路之单源最短路(SPFA)

    3.1最短路之单源最短路(SPFA) 松弛:常听人说松弛,一直不懂,后来明白其实就是更新某点到源点最短距离. 邻接表:表示与一个点联通的所有路. 如果从一个点沿着某条路径出发,又回到了自己,而且所经过 ...

  3. HDU 1052 Tian Ji -- The Horse Racing(贪心)(2004 Asia Regional Shanghai)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Ch ...

  4. HDU 1087:Super Jumping! Jumping! Jumping!(LIS)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  5. HDU 1358 Period (kmp求循环节)(经典)

    <题目链接> 题目大意: 意思是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第 ...

  6. HDU 2491 Priest John's Busiest Day(贪心)(2008 Asia Regional Beijing)

    Description John is the only priest in his town. October 26th is the John's busiest day in a year be ...

  7. HDU - 6400 多校8 Parentheses Matrix(构造)

    Parentheses Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  8. hdu多校第三场 1006 (hdu6608) Fansblog Miller-Rabin素性检测

    题意: 给你一个1e9-1e14的质数P,让你找出这个质数的前一个质数Q,然后计算Q!mod P 题解: 1e14的数据范围pass掉一切素数筛法,考虑Miller-Rabin算法. 米勒拉宾算法是一 ...

  9. hdu 1028 Ignatius and the Princess III(母函数)

    题意: N=a[1]+a[2]+a[3]+...+a[m];  a[i]>0,1<=m<=N; 例如: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + ...

随机推荐

  1. python hmac-sha1

    def getSignature(Token,paramss1): s = getParam(paramss1) print(s) # for k, v in paramss1.items(): # ...

  2. JS中千分位的处理

    function commafy(num) { //1.先去除空格,判断是否空值和非数 num = num + ""; num = num.replace(/[ ]/g, &quo ...

  3. python setup.py install 报错ImportError: No module named setuptools

    学习光荣之路python课程时,使用python setup.py install安装其他模块时,第一次安装某模块成功了.安装另一模块却报错ImportError: No module named s ...

  4. TCP跟UDP乱侃

    原文链接http://www.cnblogs.com/xiaoEight/archive/2013/02/19/2917814.html 由于最近在恶补关于网络编程的东西,所以决定做个简单的记录.之前 ...

  5. 安装linux工作环境

    1,介绍Vagrant 我们做web开发的时候经常要安装各种本地测试环境,比如apache,php,mysql,redis等等.出于个人使用习惯,可能我们还是比较习惯用windows.虽然说在wind ...

  6. HDU 1079 Calendar Game 博弈

    题目大意:从1900年1月1日 - 2001年11月4日间选择一天为起点,两个人依次进行两种操作中的任意一种,当某人操作后为2001年11月4日时,该人获胜.问先手是否获胜 操作1:向后移一天 操作2 ...

  7. try{}catch{}finally{}的手记

    try{ System.out.println("执行try"); int = 6 / 0; return 1; }catch(Exception e){ System.out.p ...

  8. Hibernate5-课程笔记3

    详解Hibernate的API: (1)Configuration接口: org.hibernate.cfg.Configuration接口的作用是加载主配置文件及映射文件,以实现对Hibernate ...

  9. 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage“提示信息

        在安装过vs2015之后出现未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage“提示信息在VS的安装目录下,找到 ...

  10. 学习前端前必知的——HTTP协议详解

    前端人士必备的知识点,无论你是否有经验,看了此文绝对有收获 此文针对前端爱好者,前端求职者(话说面试时很容易考到哦) 原文参考博客园http://kb.cnblogs.com/page/130970/ ...