CodeForces 1093C Mishka and the Last Exam

题意:

给定n/2个数,每个数拆分成两个数,将这两个数分别置于首尾(次首、次尾逐渐内缩)要求排列后这个序列是非递减的,要求你输出这个序列。

思路:
率先想到0 + a[i],判断首尾是否满足条件,满足就插入,不满足就内缩。

Code

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const LL maxn = 1e5+5;

LL a[maxn];
vector<LL> v;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n / 2; i++) cin >> a[i];
	v.push_back(0);
	v.push_back(a[0]);
	LL ps = 0, pe = a[0];
	for (int i = 1; i < n / 2; i++)
	{
		if (a[i] > pe)
		{
			LL pps = a[i] - pe;
			LL ppe = pe;

			if (pps < ps)
			{
				ppe -= (ps - pps);
				v.push_back(ps);
				v.push_back(ppe);
				pe = ppe;
			}
			else
			{
				v.push_back(pe);
				v.push_back(a[i] - pe);
				ps = a[i] - pe;
			}
		}
		else
		{
			if (0 < ps)
			{
				v.push_back(ps);
				v.push_back(a[i] - ps);
				pe = a[i] - ps;
			}
			else
			{
				v.push_back(0);
				v.push_back(a[i]);
				pe = a[i];
			}
		}
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++)
	{
		if (i) cout << " ";
		cout << v[i];
	}
	cout << endl;
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

水能zai舟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值