Zoj 3798 ABS Problem)

Source: Internet
Author: User

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)

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.