Abs Problem
Time Limit: 2 Seconds
Memory Limit: 65536 KB
Special Judge
Alice and Bob is playing a game, and this time the game is all about the absolute value!
Alice has N different positive integers, and each number is not greater than N. Bob has a lot of blank paper,and he is responsible for the calculation things. The rule of game is pretty simple. First, Alice chooses a number a1 fromthe N integers, and Bob will write it down on the first paper, that's b1. Then in the following kth rounds, Alice will choose a number ak (2 ≤ k ≤ N), then Bob will write the number bk=|ak-bk-1| on thekth paper. |x| means the absolute value of x.
Now Alice and Bob want to kown, what is the maximum and minimum value of bN. And you should tell them how to achieve that!
Input
The input consists of multiple test cases;
For each test case, the first line consists one integer N, the number of integers Alice have.(1 ≤ N
Output
For each test case, firstly print one line containing two numbers, the first one is the minimum value, and the second is the maximum value.
Then print one line containing N numbers, the order of integers that Alice should choose to achieve the minimum value.Then print one line containing N
Attention: Alice won't choose a integer more than twice.
Sample Input
2
Sample Output
1 1 1 2 2 1
链接:click here~~
题意:Alice和Bob玩数字游戏, 这次Alice和Bob玩的是绝对值游戏. (Alice和Bob以前只玩博弈类游戏, 现在开始玩数列了,^_^)
Alice有n个数(分别是1~n), 然后Alice随机从N个数中取数, 组成一个数列{A(i)}.
Bob来构建{B(i)}数列, 满足如下规则:
B(1) = A(1)
B(i) = | A(i) - B(i-1) | 即取绝对值 (i>=2 && i<=n)
目标是: 所有序列中B(n)的最小值和最大值, 并且构造它们的一种可能序列.
【解题思路】
这种题目,可以猜测该题是规律题, 那么我们来找找规律, 看看其满足什么样的规律?
枚举2, 3, 4的情况
1). 当n=2时, (1, 2)的最小值为1(2, 1), 最大值为1(2, 1) ,注意 B(i) = | A(i) - B(i-1)|
2). 当n=3时, (1, 2, 3)的最小值为0(3, 2, 1), 最大值为2(1, 2, 3)
3). 当n=4时, (1, 2, 3, 4)的最小值为0(4, 3, 2, 1), 最大值为4(3, 2, 1, 4)
要构造一个输出序列,{n, n-1, ..., 4, 3, 2, 1}, 观察得这必然是最小的序列之一
再来分析奇偶性,可以发现, 奇数时B(n)最小值为1, 偶数时B(n)最小值为0
ps :同时我们可以大胆猜测, B(n)最大取值 = n - B(n - 1)的最小值, 即 序列{ B(n) }={ 最小值 B(n -1 )序列, n },暂时证明略~~
代码: