第四届吉林省大学生程序设计大赛个人解题报告 Problem C: The Natural Series

                 Problem C: The Natural Series


The natural series, from 1 to n and rewinding, has a special character. If you add two values whose distance is 2, the sum can be divided by the middle value exactly. Let’s check a example “1 2 3 4 5 6” (and rewinding to 1): (1+3)%2==0; (2+4)%3==0; … ;(5+1)%6==0, and (6+2)%1==0. This character is unusual. You can’t find another series when n is even, and only one different series essentially when n is odd. For example, when n is 7, the other one is “1 2 3 7 4 5 6”. Here we relax the constraints. If the sum of two numbers is less than the middle value, this series can be accepted also. For example, “1 2 7 4 9 5 11 3 10 6 8” is true where 5+3<11.

Input
Each line of input has two numbers, the first is n  (4<=n<=16). The next positive integer m (1<m<=n) is a reference that you must use it to be the second number in result series.

Output
Print each series under above conditions in one line in sequence. The first number must be 1, and second is the given reference. There is a blank between adjacent numbers in one line and no blank after the last number. Print a blank between each case and also no blank line after last case.

Sample Input
10 4
7 2

Sample Output
1 4 2 6 10 3 8 5 7 9
1 4 2 8 6 10 3 5 7 9
 
1 2 3 4 5 6 7
1 2 3 7 4 5 6
 

这是一道很简单的DFS,类似于JOJ的那道素数环的题。题目大意是,找到序列S(1,2,...,N)的一个排列S',使得S'[i]+S'[i+2] < S'[i+1] 或者 (S'[i] + S'[i+2] % S'[i+1]) == 0,因为N最大也就16,所以暴力枚举每一种情况,输出合理的情况即可。不过得注意这道题的输出格式,在每两个元素之间有空格,但是最后一个元素之后不能有空格,在最后一个CASE之后也不能输出空行。

(好久没有写这种DFS了...写得很丑)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值