[整理]ACM详解(7)——压缩与编码
杰拉斯 | 时间:2012-02-17, Fri | 6,761 views编程算法
有些题目会给出一些简单的压缩方法或者编码方法,让你实现具体的算法。下面通过题目分析。
有些题目会给出一些简单的压缩方法或者编码方法,让你实现具体的算法。下面通过题目分析。
递归在解决一些问题的时候非常直观,但是在是使用递归的时候要注意递归的深度,如果深度太深,可能会造成堆栈溢出。下面通过实例介绍如何使用。
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.