日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【数学】Birthday

發布時間:2025/3/8 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【数学】Birthday 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目:

Cowboy Vlad has a birthday today! There are?nn?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 arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult 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?11?to?nn?in a circle order, that is, for every?ii?child with number?ii?will stand next to the child with number?i+1i+1, also the child with number?11?stands next to the child with number?nn. Then we will call the discomfort of the circle the maximum 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?nn?(2≤n≤1002≤n≤100)?— the number of the children who came to the cowboy Vlad's birthday.

The second line contains integers?a1,a2,…,ana1,a2,…,an?(1≤ai≤1091≤ai≤109) denoting heights of every child.

Output

Print exactly?nn?integers?— heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.

If there are multiple possible answers, print any of them.

Examples

input

Copy

5 2 1 1 3 2

output

Copy

1 2 3 2 1

input

Copy

3 30 10 20

output

Copy

10 20 30

Note

In the first example, the discomfort of the circle is equal to?11, since the corresponding absolute differences are?11,?11,?11?and?00. Note, that sequences?[2,3,2,1,1][2,3,2,1,1]?and?[3,2,1,1,2][3,2,1,1,2]?form the same circles and differ only by the selection of the starting point.

In the second example, the discomfort of the circle is equal to?2020, since the absolute difference of?1010?and?3030?is equal to?2020.

題目大意:不同身高的人圍成一圈,問怎樣排列才能使身高差異最小

解決方法:本題是想求一種能將兩數之間差值最小化的排列方式,因為是環形排列,所以僅需先將原數組從小到大排序,在依照左邊一個a1,右邊一個a2,依次即可。

AC代碼:

#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <set> #include <utility> #include <sstream> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; #define inf 0x3f3f3f3f #define rep(i,l,r) for(int i=l;i<=r;i++) #define lep(i,l,r) for(int i=l;i>=r;i--) #define ms(arr) memset(arr,0,sizeof(arr)) //priority_queue<int,vector<int> ,greater<int> >q; const int maxn = (int)1e5 + 5; const ll mod = 1e9+7; int a[120]; int b[120]; int main() {#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int n;cin>>n;rep(i,1,n) cin>>a[i];sort(a+1,a+1+n);for(int i=1,j=1;i<=n;i+=2,j++) {b[j]=a[i];b[n-j+1]=a[i+1];}if(n%2!=0) b[n/2+1]=a[n];rep(i,1,n-1) cout<<b[i]<<" ";cout<<b[n]<<endl;return 0; }

?

總結

以上是生活随笔為你收集整理的【数学】Birthday的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。