Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always be 1. Input n (0 < n < 20). Output The output format is shown as sample below. Each row represents a series of circle numbers in the ring beginning from 1 clockwisely and anticlockwisely. The order of numbers must satisfy the above requirements. Print solutions in lexicographical order. You are to write a program that completes above process. Print a blank line after each case. Sample Input
Sample Output
本题就是考递归搜索的能力。 数据不大,其他Prime, map等的优化都没多大作用的。 记得记录好数据,就不会有问题了。 不过HDU的判断系统的确垃圾,其他OJ都不会在意末尾多一个空格或者回车的问题的,HDU就一个空格一个回车都一定要按照她的格式,否则就presentation error.
|
hdoj--1016--Prime Ring Problem(递归回溯)
最新推荐文章于 2022-07-31 17:07:52 发布