C. Birthday

C. Birthday

C.生日

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input. standard input
投入。标准输入

output: standard output
产出:标准产出

Cowboy Vlad has a bithday today! There are n children who came to the celebration. In order
牛仔弗拉德今天有一天!有许多孩子来参加庆祝活动。有条不紊

to greet Vlad, the children decided to form a circle around him. Among the children who came,
为了迎接弗拉德,孩子们决定在他周围围成一个圈。在来的孩子中,

there are both tall and low, so if they stand in a circle arbitrarly, it may turn out, that there is a
有高有低,所以如果他们任意站成一个圆圈,可能会发现,有一个

tall and low child standing next to each other, and it will be dificult for them to hold hands.
高个子和矮个孩子站在一起,他们牵着手,这将是很困难的。

Therefore, children want to stand in a circle so that the maximum difference between the
因此,孩子们想要站在一个圆圈里,以便最大限度地区别于

growth of two neighboring children would be minimal possible.
两个相邻的孩子成长的可能性很小。

Formally, let’s number children from 1 to n in a circle order, that is, for every i child with
形式上,让我们用一个循环顺序从1到n,也就是,对于每一个i子

number i will stand next to the child with numberi + 1, also the child with number 1 stands
我将站在数字i+1的孩子旁边,第一位的孩子也站在旁边。

next to the child with number n. Then we will call the discomfort of the circle the maximum
其次是数n的孩子,然后我们称这个圆圈的不适度为最大值。

absolute difference of heights of the children, who stand next to each other.
绝对的身高差异的孩子,谁站在一起。

Please help children to find out how they should reorder themselves, so that the resulting
请帮助孩子们找出他们应该如何重新排序自己,从而使结果

discomfort is smallest possible .
不适是最小的可能。

Input
输入

The first line contains a single integer n(2 < n≤100)一the number of the children who
第一行包含一个整数n(2<n≤100)一

came to the cowboy Vlad’s birthday.
参加了牛仔弗拉德的生日。

The second line contains integers a1, a.,…,.n(1≤aq≤109) denoting heights of every
第二行包含表示每一个高度的整数A1、a.、.、.N(1≤aq≤109)。

child.
孩子。

Output
输出量

Print exactly n integers一heights of the children in the order in which they should stand in a
精确地打印n个整数一高度,按子元素应站在一个或多个位置的顺序排列。

circle. You can start printing a circle with any child.
绕圈。你可以开始和任何孩子一起打印一个圆圈。

If there are multiple possible answers, print any of them.
如果有多个可能的答案,请打印其中任何一个。

重大到小依次向两边排


int n, a[100007];
int ans[1000007];
int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    sort(a+1, a+n+1);
    for (int i = 0; i < n; ++i) {
        ans[i]=0;
    }
    ans[n] = a[n];
    for(int i = 1, j = -1; i <= n; ++i,j*=(-1)){
        ans[n+(i+1)/2*j] = a[n-i];
    }
    for(int i = 1; i <= 2*n; ++i)
        if(ans[i]>0)
            cout << ans[i] << " ";
        cout << endl;

        return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值