YTU 2732:3798-Abs Problem
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;
}
#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的更多相关文章
- zoj Abs Problem
Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is pl ...
- ACM YTU 挑战编程 字符串 Problem A: WERTYU
Problem A: WERTYU Description A common typing error is to place yourhands on the keyboard one row to ...
- YTU 1001: A+B Problem
1001: A+B Problem 时间限制: 1 Sec 内存限制: 10 MB 提交: 4864 解决: 3132 [提交][状态][讨论版] 题目描述 Calculate a+b 输入 Tw ...
- YTU 1012: A MST Problem
1012: A MST Problem 时间限制: 1 Sec 内存限制: 32 MB 提交: 7 解决: 4 题目描述 It is just a mining spanning tree ( 最 ...
- ZOJ Monthly, August 2014
A Abs Problem http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5330 找规律题,构造出解.copyright@ts ...
- 浙大月赛ZOJ Monthly, August 2014
Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...
- AtCoder Regular Contest 107(VP)
Contest Link Official Editorial 比赛体验良好,网站全程没有挂.题面简洁好评,题目质量好评.对于我这个蒟蒻来说非常合适的一套题目. A. Simple Math Prob ...
- YTU 1098: The 3n + 1 problem
1098: The 3n + 1 problem 时间限制: 1 Sec 内存限制: 64 MB 提交: 368 解决: 148 题目描述 Consider the following algor ...
- ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor
Description Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way ...
随机推荐
- 并发编程学习笔记(13)----ConcurrentLinkedQueue(非阻塞队列)和BlockingQueue(阻塞队列)原理
· 在并发编程中,我们有时候会需要使用到线程安全的队列,而在Java中如果我们需要实现队列可以有两种方式,一种是阻塞式队列.另一种是非阻塞式的队列,阻塞式队列采用锁来实现,而非阻塞式队列则是采用cas ...
- 梦想CAD控件安卓界面控制
CAD控件界面上所有元素都可以控制显示或隐藏,下面将逐一介绍详细用法. 设置工具文件 MxFunction.setToolFile 设置工具文件.详细说明如下: 参数 说明 String sFile ...
- java虚拟机(四)--内存溢出、内存泄漏、SOF
学习了java运行时数据区,知道每个内存区域保存什么数据,可以参考:https://www.cnblogs.com/huigelaile/p/diamondshine.html,然后了 解内存溢出和内 ...
- 【转载】dubbo约束的引入(解决eclipse中报错问题)
在采用分布式系统架构时,我们会经常使用到阿里巴巴的dubbo的分布式框架. 在相关xml配置了dubbo的约束依赖后,即使能上网eclipse.myeclipse等IDE也是无法识别dubbo的相关约 ...
- C语言scanf函数详细解释(转载)
原文地址:https://blog.csdn.net/21aspnet/article/details/174326 scanf 函数名: scanf 功 能: 执行格式化输入 用 法: int sc ...
- 搭建一台功能简单的FTP服务器
#vi /etc/sysconfig/network-scripts/ifcfg-eno33554952 #revice network restart #ping www.baidu.com #ip ...
- unbuntu 安装软件
下载ubutun镜像---------------------用win32diskimager将镜像文件写入u盘,使用u盘启动安装系统. 安装软件--------------------- 0,基本工 ...
- 可以通过dict[key]获得dict[value]
dict={key:value,key2:value2} print (dict[key] ) 得到的是 dict[value] # 软文预存接口,通过key来预览未保存的软文,联查商品.kol ...
- 【09】AngularJS 表格
AngularJS 表格 ng-repeat 指令可以完美的显示表格. 在表格中显示数据 使用 angular 显示表格是非常简单的: <div ng-app="myApp" ...
- 【Codeforces 682C】Alyona and the Tree
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设dis[v]表示v以上的点到达这个点的最大权值(肯定是它的祖先中的某个点到这个点) 类似于最大连续累加和 当往下走(x,y)这条边的时候,设 ...