Zoj 3798 ABS Problem

Source: Internet
Author: User


Finding rules ....


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 from the n integers, and Bob will write it down on the first paper, that's B1 . then in the following K TH rounds, alice will choose a number AK ( 2 ≤ k ≤ n ), then Bob will write the number BK = | AK - bk-1 | on the K TH paper. | x | means the absolute value of x .

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.



# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int N; int main () {While (scanf ("% d", & N )! = EOF) {If (n = 1) {puts ("1 1"); puts ("1"); puts ("1"); continue ;} if (n = 2) {puts ("1 1"); puts ("1 2"); puts ("2 1"); continue;} int b1 = n, b2 = n-1; For (INT I = 2; I <= N; I ++) {b1 = ABS (B1-(N-I + 1 ));} for (INT I = 2; I <n; I ++) {b2 = ABS (B2-(N-I);} b2 = ABS (b2-n ); printf ("% d \ n", b1, b2); printf ("% d", n); For (INT I = 2; I <= N; I ++) {printf ("% d", n-I + 1);} putchar (10); printf ("% d", n-1 ); for (INT I = 2; I <n; I ++) {printf ("% d", n-I);} printf ("% d", N ); putchar (10);} 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.