CF125D.Two progressions
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
An arithmetic progression is such a non-empty sequence of numbers where the difference between any two successive numbers is constant. This constant number is called common difference. For example, the sequence 3, 7, 11, 15 is an arithmetic progression. The definition implies that any sequences whose length equals 1 or 2 are arithmetic and all sequences whose length equals 0 are non-arithmetic.
You are given a sequence of different integers _a_1, _a_2, ..., a__n. You should either split it into two arithmetic progressions or find out that the operation is impossible to perform. Splitting assigns each member of the given sequence to one of two progressions, but the relative order of numbers does not change. Splitting is an inverse operation to merging.
等差数列是指一个非空的数字序列,其中任意两个相邻数字之间的差值恒定。该恒定数值称为公差。例如,序列 3,7,11,15 是一个等差数列。根据定义,长度为 1 或 2 的任意序列均为等差数列;而长度为 0 的序列(即空序列)则不视为等差数列。
给定一个由互不相同的整数组成的序列 a1,a2,…,an。你需要将该序列划分为两个等差数列,或者判定该操作无法实现。划分要求将原序列中的每个元素分配至两个等差数列之一,但各数在各自所属数列中的相对顺序必须保持不变。划分是合并操作的逆过程。
输入格式
The first line contains a positive integer n (2 ≤ n ≤ 30000), n is the length of the given sequence. The second line contains elements of the given sequence _a_1, _a_2, ..., a__n ( - 108 ≤ a__i ≤ 108). The elements of the progression are different integers.
第一行包含一个正整数 n(2≤n≤30000),n 表示给定序列的长度。第二行包含给定序列的元素 a1,a2,...,an(−108≤ai≤108)。等差数列中的元素均为互不相同的整数。
输出格式
Print the required arithmetic progressions, one per line. The progressions can be positioned in any order. Each progression should contain at least one number. If there's no solution, then print "No solution" (without the quotes)in the only line of the input file. If there are several solutions, print any of them.
按行输出所需的等差数列。这些等差数列的顺序可以任意。每个等差数列至少应包含一个数。若无解,则在输入文件的唯一一行中输出“No solution”(不带引号)。若存在多个解,输出其中任意一个即可。
输入输出样例
输入#1
6 4 1 2 7 3 10
输出#1
1 2 3 4 7 10
输入#2
5 1 2 3 -2 -7
输出#2
1 2 3 -2 -7
说明/提示
In the second sample another solution is also possible (number three can be assigned to the second progression): 1, 2 and 3, -2, -7.
在第二个样例中,还存在另一种解法(数字 3 可以分配给第二个等差数列):1, 2 和 3, -2, -7。
输入解题思路,AI测评打分。不知道怎么写?