当前位置:网站首页>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;
}
}
边栏推荐
- After modifying the background of jupyter notebook and adding jupyterthemes, enter 'JT -l' and the error 'JT' is not an internal or external command, nor a runnable program
- 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
- Usage of xcolor color in latex
- qt--將程序打包--不要安裝qt-可以直接運行
- COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况---材料的添加
- 云原生应用开发之 gRPC 入门
- Mysql database (2)
- Version 2.0 de tapdata, Open Source Live Data Platform est maintenant disponible
- 2022 operation certificate examination for main principals of hazardous chemical business units and main principals of hazardous chemical business units
- COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况----几何模型的建立
猜你喜欢
QT--创建QT程序
qt--将程序打包--不要安装qt-可以直接运行
2、TD+Learning
Gnuradio 3.9 using OOT custom module problem record
2022 free test questions of fusion welding and thermal cutting and summary of fusion welding and thermal cutting examination
Problems of font legend and time scale display of MATLAB drawing coordinate axis
About snake equation (3)
Running OFDM in gnuradio_ RX error: gr:: Log: info: packet_ headerparser_ b0 - Detected an invalid packet at item ××
2、TD+Learning
Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method
随机推荐
滑环使用如何固定
pb9.0 insert ole control 错误的修复工具
小金额炒股,在手机上开户安全吗?
Guojingxin center "friendship and righteousness" - the meta universe based on friendship and friendship, and the parallel of "honguniverse"
MySQL数据库(2)
2022 free test questions of fusion welding and thermal cutting and summary of fusion welding and thermal cutting examination
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
2022 high voltage electrician examination skills and high voltage electrician reexamination examination
Probability distribution
云原生应用开发之 gRPC 入门
The beauty of Mathematics -- the principle of fine Fourier transform
DataWorks值班表
3. Multi agent reinforcement learning
Break algorithm --- map
About snake equation (1)
Kafka-connect将Kafka数据同步到Mysql
2022 safety officer-c certificate examination summary and safety officer-c certificate reexamination examination
redis的持久化方式-RDB和AOF 两种持久化机制
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!!!
能力贡献 GBASE三大解决方案入选“金融信创生态实验室-金融信创解决方案(第一批)”