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\n",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("\n");
28
29     for(int i=n-1;i>=1;i--)
30     {
31         printf("%d ",i);
32     }
33     printf("%d\n",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\n");
44             printf("1\n");
45             printf("1\n");
46             continue;
47         }
48         if(n==2)
49         {
50             printf("1 1\n");
51             printf("1 2\n");
52             printf("2 1\n");
53             continue;
54         }
55         solve(n);
56     }
57     return 0;
58 }


时间: 2024-10-19 01:32:10

zoj Abs Problem的相关文章

ZOJ 3798 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

ZOJ 3798 Abs Problem(规律题)

题目链接: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 has

组队赛#1 解题总结 ZOJ 3798 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.

ZOJ 3789 Abs Problem

有时候像这种题,没有明显的思路,感觉像规律题.那么先暴力打表,再找规律就很快了. 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3798 先上我的暴力打表,这种肯定是TLE的,只用它发现规律就好了. #include<cstdio> #include<cstring> #include<algorithm> #define INF 0x3f3f3f3f #define N 100 us

ZOJ 3959: Problem Preparation

Problem Preparation ///@author Sycamore, ZJNU ///@date 4/22/2017 #include <iostream> #include <sstream> #include <iomanip> #include <cmath> #include <string> #include <algorithm> #include <numeric> #include <fu

ZOJ3798 Abs Problem

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3798 学会了对于序列用next_permutation暴力打表 可以先打表找规律 #include<cstdio> #include<algorithm> #define INF 0x3f3f3f3f// #define N 100 using namespace std; int seq[N];//保存当前序列 int mi[N], ma[N];//

ZOJ 3777 Problem Arrangement(状压DP)

题目链接 : http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5264 //今年省赛的题目,比赛的时候知道是状压却一直没搞出,直到最后.虽然赛后知道做法,也一直没做的,最近想不开就来做了 - -, 顺便用了下快速枚举k-子集. 恩, 做法么就是开dp[i][j] i已经选过了的题目的一个集合,j表示的是获得了j分,然后就可以直接做了..(但是好像说会T或者卡空间,我的做法是快速枚举k-子集,这个东西可以看下watashi翻译的

zoj 3777 Problem Arrangement

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5264 题意:给出n道题目以及每一道题目不同时间做的兴趣值,让你求出所有做题顺序中兴趣值大于等于m的比例.用一个分数表示. 状压dp. 枚举每一个状态,用二进制表示.dp[i][j]表示第i个题目,兴趣值为j的个数. 转移方程 dp[i|(1<<j)][k+a[num][j]]+=dp[i][k];兴趣值大于m的为 dp[1|(1<<j)][m]+=dp[i][k

HDU 3788 zoj问题

ZOJ问题 Problem Description 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. 是否AC的规则如下:1. zoj能AC:2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空:3. 若azbjc 能AC,则azbojac也能AC,其中a,b,c为N个'o'或者为空: Input 输入包含多组测试用例,每行有一个只包含'z','o','j'三种字符的字符串,字符串长度小于等于1000: Output 对于给定的字符串,如果能AC