博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Here We Go(relians) Again
阅读量:7009 次
发布时间:2019-06-28

本文共 6746 字,大约阅读时间需要 22 分钟。

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 29 * 9 *6 v 0 * 8 v3 * 7 *3 * 6 v 3 *4 * 8 *2 29 * 9 *6 v 9 * 8 v3 * 7 *3 * 6 v 3 *4 * 8 *2 29 * 9 *6 ^ 0 * 8 ^3 * 7 *3 * 6 ^ 3 *4 * 8 *0 0
 
Sample Output
1715 blips1295 blipsHoliday
 
 
Source
Mid-Central USA 2007
 
Recommend
teddy
 
/*n*m的矩阵,然后求最短路,。——。——。|   |    |。——。——。|   |    |。——。——。从上往下每一行的边,一次输入然后*表示双向,<>^V分别表示上下左右单向联通*///#include
#include
#include
#include
#define N 1100#define INF 0x3f3f3f3fusing 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[2];void dijkstra(int s){ memset(vis,0,sizeof vis); int i,j,minn,pos; memset(vis,0,sizeof(vis)); for(i = 1; i<=all; i++) dis[i] = mapn[s][i]; dis[s]=0; vis[s]=1; for(i = 1; i<=all; i++){ minn = INF; for(j = 1; j<=all; j++){ if(dis[j]
'){ mapn[((i+1)/2-1)*(m+1)+j][((i+1)/2-1)*(m+1)+j+1]=2520/val; } } } else{
//为偶数行的时候 /* 这一行第一个点是(i-1)*m+j */ for(int j=1;j<=m+1;j++){ scanf("%d%s",&val,&op); //cout<
<<" "<
<<" "; if(val==0) continue; if(op[0]=='*'){ mapn[(i/2-1)*(m+1)+j][(i/2)*(m+1)+j]=mapn[(i/2)*(m+1)+j][(i/2-1)*(m+1)+j]=2520/val; } else if(op[0]=='^'){ //上 mapn[(i/2)*(m+1)+j][(i/2-1)*(m+1)+j]=2520/val; } else if(op[0]=='v'){ //下 mapn[(i/2-1)*(m+1)+j][(i/2)*(m+1)+j]=2520/val; } } } getchar(); //cout<

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6178558.html

你可能感兴趣的文章
知方可补不足~说说吧!timestamp有什么用?
查看>>
[LeetCode] Best Time to Buy and Sell Stock
查看>>
微信公众帐号开发教程第3篇-开发模式启用及接口配置(转)
查看>>
第 12 章 Other Web Server
查看>>
.NET项目web自动化测试实战——Selenium 2.0
查看>>
[LeetCode] Split Concatenated Strings 分割串联字符串
查看>>
Asp.Net SignalR - 持久连接类
查看>>
11.8. NAT
查看>>
PowerShell调用jira rest api实现jira统计自动化
查看>>
Git 时间,将代码托管到GitHub 上
查看>>
火车票秒杀攻略
查看>>
关于Asp.Net中FileUpload控件属性PostedFile.ContentType的提示
查看>>
Laravel5做权限管理
查看>>
Spring 通过Java代码装配bean
查看>>
架构重构-好文分享
查看>>
使用shell批量生成数据整合式迁移的脚本
查看>>
双11备战核武器:全链路压测今年如何升级?
查看>>
[20151021]理解dbms_xplan.display_cursor的format参数all.txt
查看>>
sql server 获取每一个类别中值最大的一条数据
查看>>
重构——49以函数取代参数(Replace Parameter with Methods)
查看>>