Here We Go(relians) Again

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 235 Accepted Submission(s): 146
 
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
Mid-Central USA 2007
 
Recommend
teddy
 
/*
n*m的矩阵,然后求最短路,
。——。——。
| | |
。——。——。 | | |
。——。——。
从上往下每一行的边,一次输入然后*表示双向,<>^V分别表示上下左右单向联通
*/
//#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 1100
#define INF 0x3f3f3f3f
using namespace std;
int mapn[N][N];//最大是21*21个点
int n,m;
int all;
int vis[N*N];
int dis[N*N];
int val;
char op[];
void dijkstra(int s){
memset(vis,,sizeof vis);
int i,j,minn,pos;
memset(vis,,sizeof(vis));
for(i = ; i<=all; i++)
dis[i] = mapn[s][i];
dis[s]=;
vis[s]=;
for(i = ; i<=all; i++){
minn = INF;
for(j = ; j<=all; j++){
if(dis[j]<minn && !vis[j]){
pos = j;
minn = dis[j];
}
}
vis[pos] = ;
for(j = ; j<=all; j++){
if(dis[pos]+mapn[pos][j]<dis[j] && !vis[j])
dis[j] = dis[pos]+mapn[pos][j];
}
}
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF&&(n+m)){
/**********************处理输入***************************/
all=(n+)*(m+);
getchar();
/*初始化*/
for(int i=;i<=all;i++){
for(int j=;j<=all;j++){
mapn[i][j]=INF;
}
mapn[i][i]=;
}
for(int i=;i<=n*+;i++){
if(i%){//如果是奇数行,输入横着的边
/*
这一行的点是(i-1)*m+j
*/
for(int j=;j<=m;j++){
scanf("%d %s",&val,op);
//cout<<val<<" "<<op<<" ";
if(val==) continue;
if(op[]=='*'){
mapn[((i+)/-)*(m+)+j][((i+)/-)*(m+)+j+]=mapn[((i+)/-)*(m+)+j+][((i+)/-)*(m+)+j]=/val;
}
else if(op[]=='<'){
mapn[((i+)/-)*(m+)+j+][((i+)/-)*(m+)+j]=/val;
}
else if(op[]=='>'){
mapn[((i+)/-)*(m+)+j][((i+)/-)*(m+)+j+]=/val;
}
}
}
else{//为偶数行的时候
/*
这一行第一个点是(i-1)*m+j
*/
for(int j=;j<=m+;j++){
scanf("%d%s",&val,&op);
//cout<<val<<" "<<op<<" ";
if(val==) continue;
if(op[]=='*'){
mapn[(i/-)*(m+)+j][(i/)*(m+)+j]=mapn[(i/)*(m+)+j][(i/-)*(m+)+j]=/val;
}
else if(op[]=='^'){//上
mapn[(i/)*(m+)+j][(i/-)*(m+)+j]=/val;
}
else if(op[]=='v'){//下
mapn[(i/-)*(m+)+j][(i/)*(m+)+j]=/val;
}
}
}
getchar();
//cout<<endl;
}
/**********************处理输入***************************/
/*
for(int i=1;i<=all;i++){
for(int j=1;j<=all;j++){
cout<<mapn[i][j]<<" ";
}
cout<<endl;
}
*/
dijkstra();
if(dis[all]==INF) puts("Holiday");
else printf("%d blips\n",dis[all]);
}
return ;
}

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

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

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

  2. CSU 1857 Crash and Go(relians)(模拟)

    Crash and Go(relians) [题目链接]Crash and Go(relians) [题目类型]模拟 &题解: 这就是要严格的按照题意说的模拟就好了,也就是:每次添加进来一个圆 ...

  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. 【HDOJ】2722 Here We Go(relians) Again

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

  5. HDU 2722 Here We Go(relians) Again

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

  6. Here We Go(relians) Again HDU2722

    处理完输入就是很简单的一题  但是输入好难 勉强找到一种能看懂的... #include<iostream> #include<stdio.h> #include<str ...

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

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

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

  9. 【转】最短路&差分约束题集

    转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...

随机推荐

  1. js中set和get的用法

    get 语句作为函数绑定在对象的属性上,当访问该属性时调用该函数. set 语法可以将一个函数绑定在当前对象的指定属性上,当那个属性被赋值时,你所绑定的函数就会被调用. eg: var log = [ ...

  2. 认识 Java Message Service

    1. Java Message Service : 是一个消息服务的标准或者说是规范,允许应用程序组件基于JavaEE平台创建.发送.接收和读取消息. 实现Java 程序与MQ Server 之间互相 ...

  3. windows Tomcat+Nginx 集群 迷你版

    一. 准备 两个Tomcat 加上Nginx 2. 创建一个公共的文件夹用于部署项目 3. Tomcat配置 配置内存 在catalina.bat 第一行增加 set JAVA_OPTS=-Xms51 ...

  4. vim 环境设定(通用)

    有没有发现,如果我们以 vim 软件来搜寻一个档案内部的某个字符串时,这个字符串会被反白,而下次我们再次以 vim 编辑这个档案时,该搜寻的字符串反白情况还是存在呢!甚至于在编辑其他档案时,如果其他档 ...

  5. SqlServer和Oracle中一些常用的sql语句5 流程控制语句

    --在sql语句中 begin...end 用来设定一个程序块 相关于c#中的{} declare @yz real,@w int --声明变量 set @w=120 --为变量赋值 if @w< ...

  6. 使用测试思路快速学习Python-适合测试工程师的学习方法

    本文采用Python doctest单元测试的方法,直接用代码学习代码,滚雪球式的迭代学习. doctest是一个python标准库自带的轻量单元测试工具,适合实现一些简单的单元测试.它可以在docs ...

  7. [Python]Codecombat攻略之远边的森林Forest(1-40关)

    首页:https://cn.codecombat.com/play语言:Python 第二界面:远边的森林Forest(40关)时间:2-6小时内容:if/else.关系操作符.对象属性.处理输入网页 ...

  8. riot.js教程【二】组件撰写准则、预处理器、标签样式和装配方法

    基本要求 一个riot标签,就是展现和逻辑的组合(也就是html和JS): 以下是编写riot标签最基本的规则: 先撰写HTML,再撰写JS,JS代码可以写在<script>标签内部,但这 ...

  9. spring中WebApplicationContextUtils类说明

    WebApplicationContextUtils是一个抽象类,其提供了一个很便利的方法来获取spring应用的上下文即WebApplicationContext. 其中的静态方法getWebApp ...

  10. git镜像仓库

    有时候我们会把一些仓库放到本地,当他更新的时候,可以使用简单命名更新他. 不是所有时间我们都有网,所以把远程的仓库作为镜像,可以方便我们查看 普通的git clone不能下载所有分支,想要简单的git ...