YTU 2732:3798-Abs Problem

2732: 3798-Abs Problem

时间限制: 1 Sec  内存限制: 128 MB  Special Judge
提交: 167  解决: 60

题目描述

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<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 1<<29
int a[50010], b[50010];
int main()
{
    int n, Min, Max;
    while (scanf("%d", &n) != EOF)
    {
        Min = 0;
        Max = 0;
        a[1] = 1;
        a[2] = 2;
        b[1] = 2;
        b[2] = 1;
        for (int i = 3; i <= n; i++)
        {
            if (i % 2)
            {
                a[i] = i;
                b[i] = b[i - 1];
                b[i - 1] = i;
            }
            else
            {
                b[i] = i;
                a[i] = a[i - 1];
                a[i - 1] = i;
            }
        }
        for (int i = 1; i <= n; i++)
        {
            Min = abs(a[i] - Min);
            Max = abs(b[i] - Max);
        }
        if (n % 2 == 0)
        {
            printf("%d %d\n", Min, Max);
            for (int i = 1; i <= n; i++)
            {
                if (i == n) printf("%d\n", a[i]);
                else printf("%d ", a[i]);
            }
            for (int i = 1; i <= n; i++)
            {
                if (i == n) printf("%d\n", b[i]);
                else printf("%d ", b[i]);
            }
        }
        else
        {
            printf("%d %d\n", Max, Min);
            for (int i = 1; i <= n; i++)
            {
                if (i == n) printf("%d\n", b[i]);
                else printf("%d ", b[i]);
            }
            for (int i = 1; i <= n; i++)
            {
                if (i == n) printf("%d\n", a[i]);
                else printf("%d ", a[i]);
            }
        }
    }
    return 0;
}

posted @ 2016-02-01 21:25  小坏蛋_千千  阅读(163)  评论(0编辑  收藏  举报