题目链接:

PKU:http://poj.org/problem?

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

  1. 2 2
  2. 9 * 9 *
  3. 6 v 0 * 8 v
  4. 3 * 7 *
  5. 3 * 6 v 3 *
  6. 4 * 8 *
  7. 2 2
  8. 9 * 9 *
  9. 6 v 9 * 8 v
  10. 3 * 7 *
  11. 3 * 6 v 3 *
  12. 4 * 8 *
  13. 2 2
  14. 9 * 9 *
  15. 6 ^ 0 * 8 ^
  16. 3 * 7 *
  17. 3 * 6 ^ 3 *
  18. 4 * 8 *
  19. 0 0

Sample Output

  1. 1715 blips
  2. 1295 blips
  3. Holiday

Source

PS:

题意比較恶心,输入更恶心。还要分东南西北四个方向!

处理一下输入,在随便用一个最短路就好了!

代码例如以下:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. using namespace std;
  6. #define INF 0x3f3f3f3f
  7. const int maxn = 547;
  8. int mapp[maxn][maxn];
  9.  
  10. int dijkstra(int start,int n)
  11. {
  12. int dis[maxn];
  13. int mark[maxn];
  14. int k, min;
  15. memset(mark,0,sizeof(mark));
  16. for(int i = 1; i <= n; i++)
  17. dis[i] = INF;
  18. dis[start] = 0;
  19. for(int i = 1; i <= n; i++)
  20. {
  21. min = INF;
  22. for(int j = 1; j <= n; j++)
  23. {
  24. if(!mark[j] && dis[j]<min)
  25. {
  26. min=dis[j];
  27. k=j;
  28. }
  29. }
  30. mark[k] = 1;
  31. for(int j = 1; j <= n; j++)
  32. {
  33. if(mapp[k][j]!=0)
  34. {
  35. if(dis[j] > dis[k]+mapp[k][j])
  36. dis[j] = dis[k]+mapp[k][j];
  37. }
  38. }
  39. }
  40. return dis[n];
  41. }
  42. int main()
  43. {
  44. int v, h, w;
  45. char dir;
  46. while(~scanf("%d%d",&v,&h))
  47. {
  48. if(v==0 && h==0)
  49. break;
  50. memset(mapp,0,sizeof(mapp));
  51. int a, b;
  52. for(int i = 0; i <= v; i++)
  53. {
  54. for(int j = 1; j <= h; j++)
  55. {
  56. scanf("%d %c",&w,&dir);
  57. if(w == 0)
  58. continue;
  59. a = i*(h+1)+j;
  60. b = a+1;
  61. int ti = 2520/w;
  62. if(dir == '*')
  63. mapp[a][b] = mapp[b][a] = ti;
  64. else if(dir == '>')
  65. mapp[a][b] = ti;
  66. else
  67. mapp[b][a] = ti;
  68. }
  69. if(i!=v)//不是最后一行
  70. {
  71. for(int j = 1; j <= h+1; j++)//多一个
  72. {
  73. scanf("%d %c",&w,&dir);
  74. if(w == 0)
  75. continue;
  76. a = i*(h+1)+j;
  77. b = a+h+1;
  78. int ti = 2520/w;
  79. if(dir == '*')
  80. mapp[a][b] = mapp[b][a] = ti;
  81. else if(dir == 'v')
  82. mapp[a][b] = ti;
  83. else
  84. mapp[b][a] = ti;
  85. }
  86. }
  87. }
  88. int tt = (v+1)*(h+1);
  89.  
  90. int ans = dijkstra(1,tt);
  91.  
  92. if(ans != INF)
  93. printf("%d blips\n",ans);
  94. else
  95. printf("Holiday\n");
  96. }
  97. return 0;
  98. }

POJ 3653 &amp; ZOJ 2935 &amp; HDU 2722 Here We Go(relians) Again(最短路dijstra)的更多相关文章

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

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

  2. POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)

    POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...

  3. POJ 3100 &amp; ZOJ 2818 &amp; HDU 2740 Root of the Problem(数学)

    题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...

  4. POJ 3652 &amp; ZOJ 2934 &amp; HDU 2721 Persistent Bits(数学 元)

    主题链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do? probl ...

  5. POJ 3654 &amp; ZOJ 2936 &amp; HDU 2723 Electronic Document Security(模拟)

    题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

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

  7. HDU 2722 Here We Go(relians) Again

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

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

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

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

随机推荐

  1. 附加数据库错误代码 - 5120【MSSQL】

    解决方法 数据库所在的文件夹右击打开属性 - 安全 - 给予Authenticated Users用户完全控制权限.然后再附加一次即可成功.

  2. Excel文件导入导出

    /**     * 导入Excel文件数据     *      * @param file 将要导入的Excel文件     * @param fileCheckKeyWord 用于判断导入文件是否 ...

  3. [ USACO 2018 OPEN ] Out of Sorts (Platinum)

    \(\\\) \(Description\) 对一长为\(N\)的数列\(A\)排序,不保证数列元素互异: 数列\(A\)中\(A[1...i]\)的最大值不大于\(A[i+1-N]\)的最小值,我们 ...

  4. PHP开发之旅-验证码功能实现

    验证码这样的功能可以说是无处不在了,接下来使用php来实现验证码这样的功能,这里我是将验证码实现抽取到一个类中独立开来,那么后面如果再使用到验证码功能,直接引入该类文件并创建该类的实例,就可以使用验证 ...

  5. html5——2D转换

    transform 属性 1.向元素应用 2D 或 3D 转换 2.该属性允许我们对元素进行旋转.缩放.移动或倾斜. 缩放与位移 transform: scale(, 0.5);//水平缩放,垂直缩放 ...

  6. python调用java API

    JPype documentation JPype is an effort to allow python programs full access to java class libraries. ...

  7. js 攻坚克难

    new new : 官方解释: 如果在一个函数前面带上new来调用,那么背地里将会创建一个连接到该函数的prototype的成员的新对象,同时this会被绑定到哪个新对象上: new 是用来创建对象的 ...

  8. linux中集群的免秘钥SSH直接登录

    这里以三台mysql的主从服务器为例:manage.master.slave1.slave2   给4个机器生成秘钥文件 以manage为例,执行命令,生成空字符串的秘钥(后面要使用公钥),命令是: ...

  9. Swift 3到5.1新特性整理

    本文转载自:https://hicc.me/whats-new-in-swift-3-to-5-1/,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有. Hipo 2.0 重写从 Swif ...

  10. java同学毕业后学习之路建议

    第一部分:对于尚未做过Java工作的同学,包括一些在校生以及刚准备转行Java的同学. 滤过: 第二部分:对于参加工作一年以内的同学. 恭喜你,这个时候,你已经拥有了一份Java的工作.这个阶段是你成 ...