zoj Abs Problem

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 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!

Input

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)

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 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.

Sample Input

2

Sample Output

1 1
1 2
2 1


题意:n个数字1-n出现次数唯一。 b1 = a1 , bi = |ai - b(i-1)| ,ai任意。求最大和最小的bn

1 2 3 4 可以抵消为0. 所以从后往前没4项化为0 ,直接%4后 转化为判断1 - 3的情况。
 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<cstring>
 4 #include<cstdlib>
 5 using namespace std;
 6 
 7 void solve(int n)
 8 {
 9     int minn ,maxn;
10     /**min**/
11     int k = n%4;
12     if(k==0 || k==3) minn = 0;
13     else minn = 1;
14 
15     /**max**/
16     int m = n-1;
17     k = m%4;
18     if(k==0 || k==3) maxn = n;
19     else maxn = n-1;
20 
21     printf("%d %d
",minn,maxn);
22     for(int i=n;i>=1;i--)
23     {
24         if(i==n) printf("%d",i);
25         else printf(" %d",i);
26     }
27     printf("
");
28 
29     for(int i=n-1;i>=1;i--)
30     {
31         printf("%d ",i);
32     }
33     printf("%d
",n);
34 
35 }
36 int main()
37 {
38     int n;
39     while(scanf("%d",&n)>0)
40     {
41         if(n==1)
42         {
43             printf("1 1
");
44             printf("1
");
45             printf("1
");
46             continue;
47         }
48         if(n==2)
49         {
50             printf("1 1
");
51             printf("1 2
");
52             printf("2 1
");
53             continue;
54         }
55         solve(n);
56     }
57     return 0;
58 }



原文地址:https://www.cnblogs.com/tom987690183/p/3933350.html