POJ 3653 & ZOJ 2935 & HDU 2722 Here We Go(relians) Again(最短路dijstra)
题目链接:
id=3653
ZJU: problemId=1934" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1934
HDU:http://acm.hdu.edu.cn/showproblem.php?
pid=2722
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
PS:
题意比較恶心,输入更恶心。还要分东南西北四个方向!
处理一下输入,在随便用一个最短路就好了!
代码例如以下:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn = 547;
int mapp[maxn][maxn]; int dijkstra(int start,int n)
{
int dis[maxn];
int mark[maxn];
int k, min;
memset(mark,0,sizeof(mark));
for(int i = 1; i <= n; i++)
dis[i] = INF;
dis[start] = 0;
for(int i = 1; i <= n; i++)
{
min = INF;
for(int j = 1; j <= n; j++)
{
if(!mark[j] && dis[j]<min)
{
min=dis[j];
k=j;
}
}
mark[k] = 1;
for(int j = 1; j <= n; j++)
{
if(mapp[k][j]!=0)
{
if(dis[j] > dis[k]+mapp[k][j])
dis[j] = dis[k]+mapp[k][j];
}
}
}
return dis[n];
}
int main()
{
int v, h, w;
char dir;
while(~scanf("%d%d",&v,&h))
{
if(v==0 && h==0)
break;
memset(mapp,0,sizeof(mapp));
int a, b;
for(int i = 0; i <= v; i++)
{
for(int j = 1; j <= h; j++)
{
scanf("%d %c",&w,&dir);
if(w == 0)
continue;
a = i*(h+1)+j;
b = a+1;
int ti = 2520/w;
if(dir == '*')
mapp[a][b] = mapp[b][a] = ti;
else if(dir == '>')
mapp[a][b] = ti;
else
mapp[b][a] = ti;
}
if(i!=v)//不是最后一行
{
for(int j = 1; j <= h+1; j++)//多一个
{
scanf("%d %c",&w,&dir);
if(w == 0)
continue;
a = i*(h+1)+j;
b = a+h+1;
int ti = 2520/w;
if(dir == '*')
mapp[a][b] = mapp[b][a] = ti;
else if(dir == 'v')
mapp[a][b] = ti;
else
mapp[b][a] = ti;
}
}
}
int tt = (v+1)*(h+1); int ans = dijkstra(1,tt); if(ans != INF)
printf("%d blips\n",ans);
else
printf("Holiday\n");
}
return 0;
}
POJ 3653 & ZOJ 2935 & HDU 2722 Here We Go(relians) Again(最短路dijstra)的更多相关文章
- HDU 2722 Here We Go(relians) Again (最短路)
题目链接 Problem Description The Gorelians are a warlike race that travel the universe conquering new wo ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...
- POJ 3652 & ZOJ 2934 & HDU 2721 Persistent Bits(数学 元)
主题链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do? probl ...
- POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)
题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang
Problem Description As we all know, machine scheduling is a very classical problem in computer scien ...
- HDU 2722 Here We Go(relians) Again
最短路,建图太麻烦,略过…… #include <cstdio> #include <cstring> #include <queue> const int INF ...
- HDU 2722 Here We Go(relians) Again (spfa)
Here We Go(relians) Again Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/ ...
- 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 ...
随机推荐
- mariadb的安装
mysql (分支 mariadb)1.安装mariadb -yum -源码编译安装 -下载rpm安装 yum和源码编译安装的区别? 1.路径区别-yum安装的软件是他自定义的,源码安装的软件./co ...
- easyui textbox 内容改变事件 增加oninpu 类似事件,
//======================利用easyui验证功能,进行内容变化监控=== =============$(function () { var CustomerService = ...
- 常用animation动画
/*编辑动画名*/ animation-name: myDemo; /*动画持续时间*/ animation-duration: 6s; /*动画方向*/ /*reverse 反向*/ /*alter ...
- 使用Dreamweaver在一张图片上添加多个热点链接
所有代码: <html> <head> <meta charset="utf-8"> <title>无标题文档</title& ...
- phpstorm如何配置xdebug?(hpStudy+PhpStorm+XDebug配置)
xdebug是什么? 初次接触,反复试了几次终于把这个xdebug给搞清楚了,类似于前端的控制台这样的东西,可以根据断点展示我们想要看的数据. 如何配置xdebug? 配置前说明: 1.phpStud ...
- 笔记《精通css》第3章 盒模型,定位,浮动,清理
第3章 盒模型,定位,浮动,清理 1.盒模型用到的属性width,height,padding,border,margin 普通文档流的上下垂直margin会叠加 2.块级框 与 行内框, 利用 ...
- Android 获取android安装apk框的安装状态(如点击取消、返回)
最近鼓捣android,碰到个问题,因为没有root权限,需要调用Intent安装apk,但需要获取用户是否安装了(如,用户点击了返回或取消),查了很多文章,最后可以解决,但有瑕疵,解决方法如下: p ...
- Appium Python API 汇总
最近在学习Python自动化,网络搜集而来,留着备用, 方便自己也方便他人.感谢总结的人! 1.contexts contexts(self): Returns the contexts within ...
- 【PL/SQL】用星号拼出金字塔
代码中首先声明了几个变量,然后使用嵌套循环去输出空格和星号,其中: 每层空格数=总层数-该层层数 每层星号数=当前层数*2-1 代码如下: declare v_number1 ); --外层循环控制金 ...
- 【译】x86程序员手册09-第3章程序指令集
注:觉得本章内容与理解操作系统不直接相关,所以本章并未看完,也就没有翻译完,放在这里中是为了保证手册的完整.有兴趣的人可以去原址查看. https://pdos.csail.mit.edu/6.828 ...