Here We Go(relians) Again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 685    Accepted Submission(s): 335

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
 
Source
 
Recommend
teddy   |   We have carefully selected several similar problems for you:  2482 2433 2923 2377 2363 
 

构图有点小麻烦,粗心WA了好几次 = =,其实是简单题。

 //0MS    260K    2045 B    C++
#include<stdio.h>
#include<string.h>
#define N 505
#define inf 0x3fffffff
struct node{
int v,d,next;
}edge[*N];
int Head[N];
int vis[N];
int d[N];
int n,edgenum;
void addedge(int u,int v,int d)
{
edge[edgenum].v=v;
edge[edgenum].d=d;
edge[edgenum].next=Head[u];
Head[u]=edgenum++;
}
void spfa(int u)
{
int Q[N],head=,tail=;
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
d[i]=inf;
d[u]=;
vis[u]=;
Q[head]=u;
while(head!=tail){
u=Q[head++];
vis[u]=;
for(int i=Head[u];i!=-;i=edge[i].next){
int v=edge[i].v;
int w=edge[i].d;
if(d[v]>d[u]+w){
d[v]=d[u]+w;
if(!vis[v]){
Q[tail++]=v;
vis[v]=;
tail%=n;
}
}
}
head%=n;
}
}
int main(void)
{
int r,c,u,v,w;
char op;
while(scanf("%d%d",&r,&c)!=EOF && (r+c))
{
memset(Head,-,sizeof(Head));
edgenum=;
for(int i=;i<*r+;i++){
int flag=i%;
for(int j=;j<c+flag;j++){
scanf("%d %c",&w,&op);
if(w==) w=inf;
else w=/w;
u=i/*(c+)+j;
if(i%) v=(i/+)*(c+)+j;
else v=u+;
//printf("**%d %c %d %d\n",w,op,u,v);
if(i%){
if(op=='*'){addedge(u,v,w);addedge(v,u,w);}
else if(op=='v') addedge(u,v,w);
else addedge(v,u,w);
}else{
if(op=='*'){addedge(u,v,w);addedge(v,u,w);}
else if(op=='>')addedge(u,v,w);
else addedge(v,u,w);
}
}
}
n=(r+)*(c+);
spfa();
if(d[n-]==inf) puts("Holiday");
else printf("%d blips\n",d[n-]);
}
return ;
}

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

    最短路,建图太麻烦,略过…… #include <cstdio> #include <cstring> #include <queue> const int INF ...

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

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

  5. hdu 2544 最短路(两点间最短路径)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2544 方法一:dijkstra算法,求两点之间最短路径. /*********************** ...

  6. hdu 1142 A Walk Through the Forest (最短路径)

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

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

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

  8. HDU - 2066 一个人的旅行(最短路径)(模板)

    d.每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有S个(草儿家到这个城市的距离设为0),草儿想去的地方有D个: 求D个城市中距离草儿家最近的距离. s.进行1次单源最短路,找出 ...

  9. HDU题解索引

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

随机推荐

  1. 从国内下载Linux的CentOS系统

    http://mirror.nsc.liu.se/centos-store/7.3.1611/isos/x86_64/

  2. 北京Uber优步司机奖励政策(12月20日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  3. JS代码优化及技巧

    案例一  对象参数独立化 情景:为多个日期文本框添加日期选择器 源代码: $('#PropertySalesAdviceExchnagedDate1').datepicker({ showOn: 'b ...

  4. 「日常训练」 Longest Run on a Snowboard (UVA-10285)

    题意 其实就是一条二维的LIS,但是还是做的一愣一愣的,多努力. 考虑$dp[i][j]$为从(i,j)出发的二维LIS的最大值,那么$dp[i][j]=max\{dp[i−di[k]][j−dj[k ...

  5. jmeter关联三种常用方法

    在LR中有自动关联跟手动关联,但在我看来手动关联更准确,在jmeter中,就只有手动关联 为什么要进行关联:对系统进行操作时,本次操作或下一次操作对服务器提交的请求,这参数里边有部分参数需要服务器返回 ...

  6. Python字符串格式化符号及转义字符含义(非常全!!!)

    字符串格式化符号含义 符号 说明 %c 格式化字符及其 ASCII 码 %s 格式化字符串 %d 格式化整数 %o 格式化无符号八进制数 %x 格式化无符号十六进制数 %X 格式化无符号十六进制数(大 ...

  7. 前端开发工程师 - 01.页面制作 - 第3章.HTML

    第3章--HTML HTML简介 Hyper Text Markup Language:超文本标记语言--用于标记网页的内容 history: html(1991)雏形 -> html4.01( ...

  8. 了解Python控制流语句——break 语句

    这篇文章主要介绍了详解Python中break语句的用法,是Python入门的呼出知识,需要的朋友可以参考下,python基础系列教程之-Python break语句 跳出循环 break 语句用以中 ...

  9. HADOOP docker(五):hadoop用户代理 Proxy user

    1.hadoop用户代理简介2.配置3.实验 1.hadoop用户代理简介 hadoop用户代理功能的作用是让超级用户superuser模拟一个普通用户来执行任务.比如用户joe通过oozie提交一个 ...

  10. 阿里校招内推C++岗位编程题第一题 空格最少的字符串

    给定一个字符串S和有效单词的字典D,请确定可以插入到S中的最小空格数,使得最终的字符串完全由D中的有效单词组成.并输出解. 如果没有解则应该输出n/a 例如: 输入: S = “ilikealibab ...