[ AGC001 D] Arrays and Palindrome

题目

Atcoder

思路




代码

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
int n, m, A[N], B[N], t[N];
int main() {
	cin >> n >> m;
	int cnt = 0;
	t[1] = 1, t[2] = m;
	for (int i = 1; i <= m && cin >> A[i]; i++)
		if (A[i] & 1) t[++cnt] = i; // 找奇数
	if (cnt > 2) return cout << "Impossible" << endl, 0; // 判无解
	if (m == 1 && A[1] == 1) return cout << "1\n1\n1\n" << endl, 0;
	if (m == 1) return cout << A[1] << "\n2\n" << A[1] - 1 << ' ' << 1 << endl, 0; 
	// 把奇数放到头尾
	swap(A[1], A[t[1]]), swap(A[m], A[t[2]]);
	for (int i = 1; i <= m; i++) cout << A[i] << ' ';
	cout << endl << (A[m] == 1 ? m - 1 : m) << endl << A[1] + 1 << ' '; // 判断一下个数
	for (int i = 2; i <= m - 1; i++) cout << A[i] << ' ';
	if (A[m] > 1) cout << A[m] - 1 << endl; // 输出
	return 0;
}
posted @ 2021-04-25 17:47  Protein_lzl  阅读(68)  评论(0)    收藏  举报