2016广东工业大学第一次月赛a









海拔

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

对于n个数,(n为奇数)a[1] , a[2 ], a[3] , ... , a[n] 。对其海拔调整后满足条件 a[i] <= a[i + 1] , a[j] <= a[j - 1] , a[i] <= a[j] 。 其中( i >= 1 && i < =(n + 1) / 2 ) 并且( j > =(n + 1) / 2 && j <= n )。 现在给你n个数,对其进行海拔调整。

Input:

第一行一个整数t(t < 10 ),表示有t组数据。 每组数据第一行一个奇数n(2 < n < 10,000),接下去的一行有n个数(0 < a[i] < 1000000),由空格分开。

Output:

输出海拔调整后的n个数,由空格分开。 注:最后一个数不能有空格。

Sample Input:

1
5
156 22 223 156 18

Sample Output:

18 22 223 156 156
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int cmp( const int &a, const int &b ){
if( a > b )
return 1;
else
return 0;
}
int t,n,h[10010],a[10010],b[10010],m;
int main()
{
    while(cin>>t)
    {
        while(t--)
        {memset(h,0,sizeof(h));
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
            cin>>n;
            for(int i=0;i<n;i++)
                cin>>h[i];
                sort(h,h+n);
                for(int i=0;i<(n+1)/2-1;i++)
                    a[i]=h[i];
                    m=0;
                for(int j=(n + 1) / 2-1;j<n;j++)
                    {b[m]=h[j];
                    m++;}
                    sort(b,b+m,cmp);
                for(int i=0;i<(n+1)/2-1;i++)
                       cout<<a[i]<<' ';
                        m=0;
                 for(int j=(n + 1) / 2-1;j<n-1;j++)
                 {
                     cout<<b[m]<<' ';
                     m++;
                 }
                 cout<<b[m]<<endl;


        }
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值