跳到正文

题解

题解:P17033 [NWERC 2020] 温泉 / Hot Springs

fish_love_cat约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年7月7日
更新
2026年7月14日
篇幅
约 1 分钟
获赞
12
题目
P17033

版本

  1. v1当前

这个东西绝对有原神吧,怎么感觉做过。建议橙。


不妨给序列排序,然后把两个指针放到中间,每次操作交替把左右指针轮流向外移动,中间的区间一定是不会缩小的。

无解是诈骗。

复杂度 O(nlog⁡n)O(n\log n),瓶颈排序。

C++
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+1+n);
    int l=n/2,r=n/2+1;
    bool op=1;
    cout<<a[r]<<' '<<a[l]<<' ';
    while(l>1||r<n){
        if(op)r++,cout<<a[r]<<' ';
        else l--,cout<<a[l]<<' ';
        op^=1;
    }
    return 0;
}
// 这是修塔尔克大人费尽心思拼命努力帮我挑选的礼物。
// 请不要再说这种话了。