内存:128  时间:1

题目描述

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 kth rounds, Alice will choose a number ak (2 ≤ k ≤ N), then Bob will write the number bk=|ak-bk-1| on the kth 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!

输入

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 ≤ 50000)

输出

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 numbers, the order of integers that Alice should choose to achieve the maximum value. Attention: Alice won’t choose a integer more than twice.

样例输入

2

样例输出

1 1
1 2
2 1

提示

代码如下

#include<stdio.h>
#include<math.h>
int main()
{
    int N,i,j,max,min;
    while(scanf("%d",&N)!=EOF)
    {
        min=N%4;
        max=(N-1)%4;
        if(min==0||min==3)
            min=0;
        else min=1;
        if(max==0||max==3)
            max=0;
        else max=1;
        printf("%d %d\n",min,N-max);

        printf("%d",N);
        for(i=N-1; i>0; i--)
            printf(" %d",i);
        printf("\n");

        printf("%d",N-1);
        for(i=N-2; i>0; i--)
            printf(" %d",i);
        printf(" %d\n",N);
    }
    return 0;
}

代码来源于互联网,仅供参考!