UVa 524 Prime ring Problem: Number theory &dfs

Source: Internet
Author: User

524-prime Ring Problem

Time limit:3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=465

A ring are composed of n (even number) circles as shown in diagram. Put natural numbers to each circle separately, and the sum of numbers in two adjacent circles be a should E.

Note: the number of the circle should always is 1.

Input

N (0 < n <= 16)

Output

The output format is shown as sample below. Each row represents a series of the circle numbers into the ring beginning from 1 clockwisely and anticlockwisely. The order of numbers must satisfy the above requirements.

You are are to write a program that completes above process.

Sample Input

6
8

Sample Output

Case 1:1 4 3 2 5 6 1 6 5 2 3 4 The case

2:
1
2 3 8 5 6 7 4 1 2 5 8 3 4 7 6 1 4 7 6 5 8 3 2 1 6 7 4 3 8 5 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.