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;
}

YTU 2732:3798-Abs Problem的更多相关文章

  1. zoj Abs Problem

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

  2. ACM YTU 挑战编程 字符串 Problem A: WERTYU

    Problem A: WERTYU Description A common typing error is to place yourhands on the keyboard one row to ...

  3. YTU 1001: A+B Problem

    1001: A+B Problem 时间限制: 1 Sec  内存限制: 10 MB 提交: 4864  解决: 3132 [提交][状态][讨论版] 题目描述 Calculate a+b 输入 Tw ...

  4. YTU 1012: A MST Problem

    1012: A MST Problem 时间限制: 1 Sec  内存限制: 32 MB 提交: 7  解决: 4 题目描述 It is just a mining spanning tree ( 最 ...

  5. ZOJ Monthly, August 2014

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

  6. 浙大月赛ZOJ Monthly, August 2014

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

  7. AtCoder Regular Contest 107(VP)

    Contest Link Official Editorial 比赛体验良好,网站全程没有挂.题面简洁好评,题目质量好评.对于我这个蒟蒻来说非常合适的一套题目. A. Simple Math Prob ...

  8. YTU 1098: The 3n + 1 problem

    1098: The 3n + 1 problem 时间限制: 1 Sec  内存限制: 64 MB 提交: 368  解决: 148 题目描述 Consider the following algor ...

  9. ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor

    Description Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way ...

随机推荐

  1. 并发编程学习笔记(9)----AQS的共享模式源码分析及CountDownLatch使用及原理

    1. AQS共享模式 前面已经说过了AQS的原理及独享模式的源码分析,今天就来学习共享模式下的AQS的几个接口的源码. 首先还是从顶级接口acquireShared()方法入手: public fin ...

  2. 创建一个 Vue 的实例

    每个 Vue 应用都是通过 Vue 函数创建一个新的 Vue 实例开始的: var vm = new Vue({         // 选项 }) 选项:el.data.methods el: 类型: ...

  3. vuex与redux,我们都一样

    vuex与redux的主要区别: redux:生成的全局数据流是通过每个组件的props逐层传递到各个子组件的,通过@connect装饰器绑定在this.props上面. vuex :生成的全局数据则 ...

  4. 微信支付开发 c#

    代码demo下载地址: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=11_1

  5. ajax aspx调用webservice,返回json

    1,创建一个asp.net网站 2.创建一个student类 using System; using System.Collections.Generic; using System.Linq; us ...

  6. CSS 嵌入,及其选择器

    CSS 1. CSS样式表的几种使用方式 1.元素内嵌 <p style="font-size"></p> 2.内部文档内嵌 <style type= ...

  7. Effective C++标题整理

    Effective C++ 话说光看这50个tip又有什么用呢?只有实际使用的时候才体现它们的价值才对. 就像只看<代码大全>不能成为一个好程序员,必须结合实际写项目经验才行. 从C转向C ...

  8. Linux:iscsi存储服务器配置

    服务器添加4块硬盘 mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde 记下UUID值 mdadm -D /de ...

  9. Import CAD geometry in BladeModeler, turbogrid

    Table of Contents 1. Import CAD geometry in BladeModeler, turbogrid 1 Import CAD geometry in BladeMo ...

  10. 2.5.5 基本的 I/0 重定向

        标准输入/输出(standard I/O)可能是软件设计原则里最重要的概念了.这个概念就是:程序应该有数据的来源端.数据的目的端以及报告问题的地方,它们分别被称为标准输入(standard i ...