当前位置:网站首页>Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences
Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences
2022-07-08 01:41:00 【Not long】
Topic link :https://codeforces.com/problemset/problem/1339/B
Their thinking : thinking + greedy
I didn't turn around at first , I've been thinking about how to put equal numbers in front , After reading the boss' solution, I knew that the method was wrong from the beginning .
Make the numbers form a special arrangement , Make two adjacent numbers in the array , The difference between the former and the latter has a non decreasing trend .
Think the other way first , How to make the difference between two adjacent numbers in an array show a non increasing trend ( It is easy to understand and analyze many ) Then output it in reverse .
Non incremental situation ( The big one is ahead ) Maximum case : Naturally, it is the difference between the maximum number and the minimum number , Because it is arranged according to the absolute value of the difference , Therefore, the latter is the minimum and the next maximum , Then there are the second small value and the second large value … Finally, the middle part ( The odd number of data is finally the middle one , An even number can be arranged according to the rule )
thus : For the requirements of the topic , Output in reverse . Without the transition of the previous situation, it may be difficult to understand why to output from the middle to both sides .
AC Code :
#include<iostream>
#include<algorithm>
using namespace std;
int num[100005];
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> num[i];
sort(num, num + n);
if (n % 2 == 1)
cout << num[n / 2] << ' ';
for (int i = n / 2 - 1; i >= 0; i--)
cout << num[i] << ' ' << num[n - i - 1] << ' ';
cout << endl;
}
}
边栏推荐
- 由排行榜实时更新想到的数状数值
- Redis master-slave replication
- GBASE观察 | 数据泄露频发 信息系统安全应如何守护
- Redux usage
- Is it safe to open an account on your mobile phone for small amount of stock speculation?
- Break algorithm --- map
- 2021-04-12 - new features lambda expression and function functional interface programming
- The Ministry of housing and urban rural development officially issued the technical standard for urban information model (CIM) basic platform, which will be implemented from June 1
- 什么样的MES系统才是好系统
- 腾讯游戏客户端开发面试 (Unity + Cocos) 双重轰炸 社招6轮面试
猜你喜欢

ANSI / nema- mw- 1000-2020 magnetic iron wire standard Latest original

COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况----几何模型的建立

2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions

图解网络:揭开TCP四次挥手背后的原理,结合男女朋友分手的例子,通俗易懂

2021 welder (primary) examination skills and welder (primary) operation examination question bank

About snake equation (3)

2021-04-12 - new features lambda expression and function functional interface programming

The persistence mode of redis - RDB and AOF persistence mechanisms

2022 examination for safety production management personnel of hazardous chemical production units and new version of examination questions for safety production management personnel of hazardous chem

用户之声 | 对于GBase 8a数据库学习的感悟
随机推荐
Scalar / vector / matrix derivation method
2、TD+Learning
The usage of rand function in MATLAB
Capability contribution three solutions of gbase were selected into the "financial information innovation ecological laboratory - financial information innovation solutions (the first batch)"
In depth analysis of ArrayList source code, from the most basic capacity expansion principle, to the magic iterator and fast fail mechanism, you have everything you want!!!
The difference between distribution function and probability density function of random variables
Optimization of ecological | Lake Warehouse Integration: gbase 8A MPP + xeos
写一个纯手写的qt的hello world
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
ArrayList源码深度剖析,从最基本的扩容原理,到魔幻的迭代器和fast-fail机制,你想要的这都有!!!
Js中forEach map无法跳出循环问题以及forEach会不会修改原数组
npm 內部拆分模塊
2022 new examination questions for crane driver (limited to bridge crane) and question bank for crane driver (limited to bridge crane) operation examination
Plot function drawing of MATLAB
common commands
powerbuilder 中使用线程的方法
Understanding of expectation, variance, covariance and correlation coefficient
The examination contents of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge) in 2021 and the free examination questions of the third batch of Guangdong Prov
MySQL数据库(2)
Gbase observation | how to protect the security of information system with frequent data leakage