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. MySQL单表数据不超过500万:是经验数值,还是黄金铁律?

    今天,探讨一个有趣的话题:MySQL 单表数据达到多少时才需要考虑分库分表?有人说 2000 万行,也有人说 500 万行.那么,你觉得这个数值多少才合适呢? 曾经在中国互联网技术圈广为流传着这么一个 ...

  2. 诊断:ORA-38760: This database instance failed to turn on flashback database

    $ oerr ora 38760 38760, 00000, "This database instance failed to turn on flashback database&quo ...

  3. oop设计模式抽象总结

    创建型模式: 一.简单工厂,工厂方法,抽象工厂 简单工厂:只有一层抽象,由工厂去获得抽象类的具体对象,工厂内的方法可以看做静态方法 工厂方法:有两个抽象,工厂的抽象和具体类的抽象. 举个例子: 有个汽 ...

  4. Django-Rest framework中文翻译-Request

    REST framework的Request类扩展自标准的HttpRequest,增加了REST framework灵活的请求解析和请求验证支持. 请求解析 REST framework的Reques ...

  5. C语言基础--数据

    c语言中数据: 在8位单片机种最常用的数据类型就是: unsigned char: 无符号字符型,位宽1个字节,8个位,表示的范围0~255(2^8-1) 在32位单片机中最常用的数据类型就是: un ...

  6. 48. spring boot单元测试restfull API【从零开始学Spring Boot】

    回顾并详细说明一下在在之前章节中的中使用的@Controller.@RestController.@RequestMapping注解.如果您对Spring MVC不熟悉并且还没有尝试过快速入门案例,建 ...

  7. mappingLocations、mappingDirectoryLocations与mappingJarLocations 区别 (转)

    mappingLocations.mappingDirectoryLocations与mappingJarLocations 区别 由于spring对hibernate配置文件hibernate.cf ...

  8. 1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛

    1267 老鼠的旅行  2012年CCC加拿大高中生信息学奥赛 题目描述 Description You are a mouse that lives in a cage in a large lab ...

  9. new出来的对象无法调用@Autowired注入的Spring Bean

    @Autowired注入Spring Bean,则当前类必须也是Spring Bean才能调用它,不能用new xxx()来获得对象,这种方式获得的对象无法调用@Autowired注入的Bean. 1 ...

  10. Java设计模式补充:回调模式、事件监听器模式、观察者模式(转)

    一.回调函数 为什么首先会讲回调函数呢?因为这个是理解监听器.观察者模式的关键. 什么是回调函数 所谓的回调,用于回调的函数. 回调函数只是一个功能片段,由用户按照回调函数调用约定来实现的一个函数. ...