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的情况。
 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; void solve(int n)
{
int minn ,maxn;
/**min**/
int k = n%;
if(k== || k==) minn = ;
else minn = ; /**max**/
int m = n-;
k = m%;
if(k== || k==) maxn = n;
else maxn = n-; printf("%d %d\n",minn,maxn);
for(int i=n;i>=;i--)
{
if(i==n) printf("%d",i);
else printf(" %d",i);
}
printf("\n"); for(int i=n-;i>=;i--)
{
printf("%d ",i);
}
printf("%d\n",n); }
int main()
{
int n;
while(scanf("%d",&n)>)
{
if(n==)
{
printf("1 1\n");
printf("1\n");
printf("1\n");
continue;
}
if(n==)
{
printf("1 1\n");
printf("1 2\n");
printf("2 1\n");
continue;
}
solve(n);
}
return ;
}


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. 转:Curl详解

    用途说明 curl命令是一个功能强大的网络工具,它能够通过http.ftp等方式下载文件,也能够上传文件.其实curl远不止前面所说的那些功能,大家可以通过man curl阅读手册页获取更多的信息.类 ...

  2. [原创]java WEB学习笔记80:Hibernate学习之路--- hibernate配置文件:JDBC 连接属性,C3P0 数据库连接池属性等

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  3. Java基础(40):Java中的集合介绍---Collection与Map

    集合类说明及区别Collection├List│├LinkedList│├ArrayList│└Vector│ └Stack└SetMap├Hashtable├HashMap└WeakHashMap ...

  4. kafka监控工具kafkaOffsetMoniter的使用

    简介 KafkaOffsetMonitor是由Kafka开源社区提供的一款Web管理界面,用来实时监控Kafka的Consumer以及Partition中的Offset,可以在web界面直观的看到每个 ...

  5. paper 37 : WINCE的BIB文件解析

    WINCE的BIB文件解析 BIB的全称为Binary Image Builder,在Wince编译过程中的最后MakeImage阶段会用到BIB文件,BIB文件的作用是指示构建系统如何构建二进制映像 ...

  6. cactive信号

    AXI中C-channel的cactive信号并不仅仅应用在CSYSREQ,CSYSACK交互中. CSYSREQ和CSYSACK信号都在低电平表示lower power的请求和应答有效. cacti ...

  7. LDA-math-认识Beta/Dirichlet分布

    http://cos.name/2013/01/lda-math-beta-dirichlet/#more-6953 2. 认识Beta/Dirichlet分布2.1 魔鬼的游戏—认识Beta 分布 ...

  8. MYSQL日期类型的加减更新使用INTERVAL 1 DAY

    例如:UPDATE teachingplan SET teachPlanBeginTime = teachPlanBeginTime +INTERVAL 1 DAY

  9. RobotFrameWork接口报文测试-----(二)demo的升级版

    在上一篇,简单的demo实现了讲xml的数据发送服务器端并取得recvi_buf,然后进行了简单的解析的操作.现在就要解决之前提过的2个问题: 1. 步骤这么多,难道每写一个脚本都要重复一次么? 2. ...

  10. tp框架支付宝手机网页支付

    开发环境:linux+php+mysql 密钥生成: 1.genrsa -out rsa_private_key.pem 1024 生成商户私钥,因在php环境,一定要保持原始状态,不得修改.rsa_ ...