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

  1. 2

Sample Output

  1. 1 1
  2. 1 2
  3. 2 1
  4.  
  5. 题意:n个数字1-n出现次数唯一。 b1 = a1 , bi = |ai - b(i-1)| ,ai任意。求最大和最小的bn
  6.  
  7. 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%;
  12. if(k== || k==) minn = ;
  13. else minn = ;
  14.  
  15. /**max**/
  16. int m = n-;
  17. k = m%;
  18. if(k== || k==) maxn = n;
  19. else maxn = n-;
  20.  
  21. printf("%d %d\n",minn,maxn);
  22. for(int i=n;i>=;i--)
  23. {
  24. if(i==n) printf("%d",i);
  25. else printf(" %d",i);
  26. }
  27. printf("\n");
  28.  
  29. for(int i=n-;i>=;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)>)
  40. {
  41. if(n==)
  42. {
  43. printf("1 1\n");
  44. printf("1\n");
  45. printf("1\n");
  46. continue;
  47. }
  48. if(n==)
  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 ;
  58. }

zoj Abs Problem的更多相关文章

  1. ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds      Me ...

  2. ACM学习历程—ZOJ 3777 Problem Arrangement(递推 && 状压)

    Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...

  3. zoj 3777 Problem Arrangement(壮压+背包)

    Problem Arrangement Time Limit: 2 Seconds      Memory Limit: 65536 KB The 11th Zhejiang Provincial C ...

  4. zoj 3777 Problem Arrangement

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5264 题意:给出n道题目以及每一道题目不同时间做的兴趣值,让你求出所有做题顺序 ...

  5. ZOJ 3959 Problem Preparation 【水】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 AC代码 #include <cstdio> ...

  6. ZOJ 3329 Problem Set (期望dp)

    One Person Game There is a very simple and interesting one-person game. You have 3 dice, namely Die1 ...

  7. 浙大月赛ZOJ Monthly, August 2014

    Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...

  8. ZOJ Monthly, August 2014

    A Abs Problem http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5330 找规律题,构造出解.copyright@ts ...

  9. HDU 1242 Rescue(BFS),ZOJ 1649

    题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...

随机推荐

  1. jvm内存设置

    JVM有很多个内存管理命令,总体而言,分为两类: 1.-X开头的管理命令:这些选项在JDK升级时不会通知修改: 2.-XX开头的管理命令:这些选项不够稳定,所以建议少用. JVM参数的含义: 参数名称 ...

  2. Codeforce Round #221 Div2

    每次的CF都是一把辛酸泪! 什么时候能打破这局面,昨天做着睡着了! 有时候有的题目也就差一线! 哎,! A:杠杆原理! B:算最后负的和! B:没弄出来当时就脑短路... C:事后写了个n*log(n ...

  3. How to export a template in Visual Studio?

    Create a customize template file: 1.template arguments introduction like: 上图只是其中一部分,更多请查看文后的参考资源 tem ...

  4. C++之路起航——标准模板库(deque)

    deque(双端队列):http://baike.baidu.com/link?url=JTvA2cuLubptctHZwFxswvlZvxNdFOxmifsYCGLj5IZF-Tj4rbWLv8Jn ...

  5. hdu5314 Happy King

    树分治. 代码 #pragma comment(linker, "/STACK:102400000,102400000") #include<cstdio> #incl ...

  6. Spring 中的 Bean 配置

    内容提要 •IOC & DI 概述 •配置 bean –配置形式:基于 XML 文件的方式:基于注解的方式 –Bean 的配置方式:通过全类名(反射).通过工厂方法(静态工厂方法 & ...

  7. Spark on Yarn

    Spark on Yarn 1. Spark on Yarn模式优点 与其他计算框架共享集群资源(eg.Spark框架与MapReduce框架同时运行,如果不用Yarn进行资源分配,MapReduce ...

  8. react编译器jsxTransformer,babel

    1.JSX是什么JSX其实是JavaScript的扩展,React为了代码的可读性更方便地创建虚拟DOM等原因,加入了一些类似XML的语法的扩展. 2.编译器——jsxTransformerJSX代码 ...

  9. Entity Framework 无法对没有主键的视图映射实体的解决办法

    我们在使用Entity Framework的时候经常会把数据库中的某一个视图映射为EF的实体,但是如果数据库视图中的列没有包含表的主键列,EF会报出警告说视图没有主键,导致视图映射为实体失败,错误如下 ...

  10. OpenStack 物理资源问题

    Contents [hide] 1 写在前面 2 openstack的自有设置 3 解决办法 4 最终解决办法 写在前面 物理CPU核数为12,能虚拟多少虚拟核的机器?openstack的默认使用no ...