Question link: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3798.
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 hasNDifferent positive integers, and each number is not greaterN. 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 numberA1FromNIntegers, and Bob will write it down on the first paper, that'sB1. Then in the followingKTh rounds, Alice will choose a numberAK(2 ≤ k ≤ n), Then Bob will write the numberBK= |AK-Bk-1| OnKTh paper. |X| Means the absolute valueX.
Now Alice and Bob want to kown, what is the maximum and minimum valueBN. And you shoshould tell them how to achieve that!
Input
The input consists of multiple test cases;
For each test case, the first line consists one integerN, The number of integers Alice have. (1 ≤N≤ 50000)
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 containingNNumbers, the order of integers that Alice shoshould choose to achieve the minimum value. Then print one line containingNNumbers, the order of integers that Alice shoshould choose to achieve the maximum value.
Attention: Alice won't choose a integer more than twice.
Sample Input
2
Sample output
1 11 22 1
Author: Zhang, Ruixiang
Source: Zoj monthly, August 2014.
This is a regular question. It is easy to find that when n = 3 or 4 is MINV = 0; when k = n % 4 is k = 0 or 3, MINV = 0, in other cases, MINV = 1 (can be pushed by small data ).
It is also easy to know that maxv = N-MINV (last time) So k = (n-1) % 4, when k = 0 | K = 3 maxv = N, otherwise maxv = n-1
# Include <iostream> # include <cstring> # include <cstdio> # include <algorithm> # include <string> # include <cmath> using namespace STD; void Gao (int n) {int K = n % 4; int MINV, maxv; If (k = 0 | K = 3) MINV = 0; else MINV = 1; k = (n-1) % 4; If (k = 0 | K = 3) maxv = N; else maxv = n-1; cout <MINV <"<maxv <Endl; for (INT I = N; I >= 1; I --) {if (I = N) cout <I; else cout <"<I ;} cout <Endl; For (INT I = n-1; I> = 1; I --) {if (I = N-1) cout <I; else Cout <"" <I ;}cout <"" <n <Endl ;}int main () {int N; while (~ Scanf ("% d", & N) {If (n = 1) {cout <1 <"" <1 <Endl; cout <1 <Endl; cout <1 <Endl; continue;} If (n = 2) {cout <1 <"" <1 <Endl; cout <1 <"" <2 <Endl; cout <2 <"" <1 <Endl; continue;} Gao (n);} return 0 ;}
Zoj 3798 ABS Problem)