ZOJ3798:Abs Problem
来源:互联网 发布:水泥掺量20 算法 编辑:程序博客网 时间:2024/09/21 09:01
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 11 22 1
#include <iostream>#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>#include <queue>#include <stack>#include <map>using namespace std;#define up(i,x,y) for(i=x;i<=y;i++)#define up2(i,x,y) for(i=x;y;i++)#define down(i,x,y) for(i=x;i>=y;i--)#define down2(i,x,y) for(i=x;y;i--)#define pi acos(-1.0)#define ll long long#define s(a) scanf("%d",&a)#define mem(a,b) memset(a,b,sizeof(a))#define ads(a) (a<0?-a:a)#define w(a) while(a)void print(int l,int r,int m){ int i=l,j=r; w(i<=j) { if(i==j) { printf("%d ",i); break; } else if(i+1>=j) { printf("%d %d ",i,j); break; } else if(i+2>=j) { printf("%d %d %d ",i,j,i+1); break; } printf("%d %d ",i,i+1); i+=2; printf("%d %d ",j,j-1); j-=2; } printf("%d",m);}int main(){ int n,sum,i,j; w(~s(n)) { sum=0; up(i,1,n) sum+=i; printf("%d %d\n",sum%2,n-(sum-n)%2); if(n%2) { print(2,n,1); printf("\n"); print(1,n-1,n); printf("\n"); } else { print(3,n,2); printf(" 1\n"); print(2,n-1,1); printf(" %d\n",n); } }}
- ZOJ3798:Abs Problem
- zoj3798 Abs Problem 水题
- Abs Problem
- (找规律)Abs Problem
- ZOJ 3798 Abs Problem
- ZOJ 3789 Abs Problem
- ZOJ 3798 Abs Problem
- ZOJ 3798 Abs Problem
- ZOJ-3798-Abs Problem
- YTU 2732:3798-Abs Problem
- ZOJ 3798 Abs Problem(规律题)
- ZOJ 3798 Abs Problem(找规律)
- ABS
- abs
- abs
- abs
- abs
- abs
- HDU题目分类
- RFID智能档案管理系统 设计方案
- 南京邮电大学OJ——1064快速排序
- 只喝果汁能减肥吗 效果怎么样
- Windows下Console和Win32程序差异
- ZOJ3798:Abs Problem
- POI运用Excel模板打印报表
- FAILED: Execution Error, return code 3 from org.apache.hadoop.hive.ql.exec.mr.MapredLocalTask
- 平均背景法提取前景
- POJ-2115
- 程序员生存定律-打造属于自己的稀缺性
- Spring@Autowired注解与自动装配 .
- Codeforces 148E Porcelain [预处理+dp背包]
- 图灵机器人下载地址