当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1792:Hexagonal Routes

题目描述
Finding the shortest route is the typical task of a truck driver. If the truck moves via the shortest route, it saves money. It is also important to know alternative routes of the same length, for the case a route is unavailable, e.g., due to some road work.

To describe a region, we need to model a map of it. ACM recently found that triangular and rectangular based models are insufficient and decided to use hexagons for describing maps. Given a regular hexagonal grid (like honeycombs), we can number the cells starting with 1 (in any particular cell) and going in a spiral-like manner to other cells. This way, each cell is uniquely identified by its number and vice versa, each positive integer identifies a single cell.

Two cells are called neighboring iff they have one side in common. In an infinite structure, each cell has exactly six neighbors. For instance, cell number 2 neighbors to cells 1, 3, 7, 8, 9 and 10. A hexagonal route is a non-empty sequence of cells where each cell in the sequence (except the last one) neighbors with its successor. A hexagonal route between two cells X and Y is a hexagonal route with X being the first member of the sequence, and Y being the last. The length of the route is the number of cells minus one. It represents the number of steps we need to make to travel via the route.

Your task is to determine the length of the shortest possible route between two cells and the total number of mutually different routes of that length. Different routes must differ in at least one sequence member, i.e., they do not need to form completely disjoint sequences.
输入解释
The input consists of a series of tasks, each of them given on one separate line. The line contains two integer numbers X and Y, separated by a space, 1 <= X, Y <= 1 000 000, X != Y. These numbers identify two different cells. The last task is followed by a line containing two zeros. This line terminates the input.
输出解释
For each task, output the sentence "There are N routes of the shortest length L.". Replace L with the smallest possible route length between cells X and Y. Replace N with the number of different routes of that length. If there is a single route only, use the words "is" and "route" instead of "are" and "routes".
输入样例
1 2
1 7
1 8
1 19
7 12
1000 9000
0 0
输出样例
There is 1 route of the shortest length 1.
There is 1 route of the shortest length 1.
There are 2 routes of the shortest length 2.
There is 1 route of the shortest length 2.
There are 3 routes of the shortest length 3.
There are 278940769844931007968 routes of the shortest length 73.

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 CTU Open 2003

源链接: POJ-1792

最后修改于 2020-10-29T06:14:07+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 30000