2732: 3798-Abs Problem

时间限制: 1 Sec  内存限制: 128 MB  Special Judge

提交: 167  解决: 60

题目描述

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!

输入

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)

输出

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.

样例输入

2

样例输出

1 1
1 2
2 1

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 1<<29
int a[50010], b[50010];
int main()
{
int n, Min, Max;
while (scanf("%d", &n) != EOF)
{
Min = 0;
Max = 0;
a[1] = 1;
a[2] = 2;
b[1] = 2;
b[2] = 1;
for (int i = 3; i <= n; i++)
{
if (i % 2)
{
a[i] = i;
b[i] = b[i - 1];
b[i - 1] = i;
}
else
{
b[i] = i;
a[i] = a[i - 1];
a[i - 1] = i;
}
}
for (int i = 1; i <= n; i++)
{
Min = abs(a[i] - Min);
Max = abs(b[i] - Max);
}
if (n % 2 == 0)
{
printf("%d %d\n", Min, Max);
for (int i = 1; i <= n; i++)
{
if (i == n) printf("%d\n", a[i]);
else printf("%d ", a[i]);
}
for (int i = 1; i <= n; i++)
{
if (i == n) printf("%d\n", b[i]);
else printf("%d ", b[i]);
}
}
else
{
printf("%d %d\n", Max, Min);
for (int i = 1; i <= n; i++)
{
if (i == n) printf("%d\n", b[i]);
else printf("%d ", b[i]);
}
for (int i = 1; i <= n; i++)
{
if (i == n) printf("%d\n", a[i]);
else printf("%d ", a[i]);
}
}
}
return 0;
}

最新文章

  1. 拉风的服务器监控工具,随时掌握服务器动态,AgileEAS.NET SOA 平台服务器监控工具集介绍
  2. Dedecms 图片加上Alt或Title等属性写法
  3. 统计字符串”aaaabbbccccddfgh”中字母个数以及统计最多字母数
  4. 4.5你太黑了,不带这么玩TypeForwardedTo的
  5. 云计算的三层SPI模型
  6. vmware虚拟机三种网络模式详解_转
  7. CSS选择器、优先级与匹配原理(转)
  8. DB Create and Insert
  9. [C#]Winform下回车或Tab键自动切换下一个控件焦点
  10. Java将整个文件夹里的文本中的字符串替换成另外一个字符串(可用于项目复制,变成另一个项目)
  11. Python串口操作纸币器1
  12. WPF 界面布局DockPanel stackPanel WrapPanel 元素内容以及位置控制
  13. 【iOS】3D Touch
  14. 5款免费Windows远程连接Linux桌面软件(VNC客户端)
  15. asp.net 分页的制作
  16. 24、手把手教你Extjs5(二十四)模块Form的自定义的设计[3]
  17. Centos7安装nginx并设置为HTTP代理服务器(正向代理)
  18. 【原】无脑操作:EasyUI Tree实现左键只选择叶子节点、右键浮动菜单实现增删改
  19. Vue的基本使用
  20. Oracle数据库查看表空间是否为自增的

热门文章

  1. 【Hadoop】一、HDFS简介及基本概念
  2. node事件循环和消息队列简单分析
  3. Extjs杂记录
  4. STL源码分析之第二级配置器
  5. UVA - 442 Matrix Chain Multiplication(栈模拟水题+专治自闭)
  6. &lt;MyBatis&gt;入门三 sqlMapper文件
  7. ndk编译libpcap 1.7.4(最终解决方法)
  8. Educational Codeforces Round 41 D. Pair Of Lines(961D)
  9. 九度oj 题目1050:完数
  10. [bzoj2055]80人环游世界[网络流,上下界网络流]