| 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-02-13 16:38:30 发布
本文介绍了一个利用递归搜索解决特定数学问题的方法:寻找满足相邻两数之和为素数条件的环状数列。通过C++代码实现了这一算法,并详细解释了如何避免重复解以及确保输出格式符合要求。
329

被折叠的 条评论
为什么被折叠?



