首页 > 其他 > 详细

Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences

时间:2020-04-20 21:09:51      阅读:52      评论:0      收藏:0      [点我收藏+]

链接:https://codeforces.com/contest/1339/problem/B

题意:给定一个数组,重排后,按绝对值递增;

排序后,从后往前一大一小输出即可;

code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll a[maxn],ans[maxn];
void solve()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
    sort(a+1,a+1+n);
    int l=1, r=n;
    for(int i=n; i>=1; i--)
    {
        if(i%2) ans[i]=a[r--];
        else ans[i]=a[l++];
    }
    for(int i=1; i<=n; i++) printf("%lld ",ans[i]);
    printf("\n");
}
int main()
{
    int t;
    cin>>t;
    while(t--) solve();
    //system("pause");
    return 0;
}

 

Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences

原文:https://www.cnblogs.com/sweetlittlebaby/p/12739921.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!