当前位置:网站首页>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;
}
}
边栏推荐
- Call (import) in Jupiter notebook ipynb . Py file
- The solution of frame dropping problem in gnuradio OFDM operation
- 项目经理有必要考NPDP吗?我告诉你答案
- 2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions
- Android 创建的sqlite3数据存放位置
- Problems of font legend and time scale display of MATLAB drawing coordinate axis
- Common operations of numpy on two-dimensional array
- 2022 high voltage electrician examination skills and high voltage electrician reexamination examination
- 5、離散控制與連續控制
- 2022 safety officer-b certificate examination question bank and safety officer-b certificate simulation test questions
猜你喜欢
2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions
LeetCode 练习——剑指 Offer 36. 二叉搜索树与双向链表
2022 R1 fast opening pressure vessel operation test question bank and R1 fast opening pressure vessel operation free test questions
Gnuradio3.9.4 create OOT module instances
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
About snake equation (3)
2022 high voltage electrician examination skills and high voltage electrician reexamination examination
Gnuradio 3.9 using OOT custom module problem record
COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况---材料的添加
2021 tea master (primary) examination materials and tea master (primary) simulation test questions
随机推荐
regular expression
The foreach map in JS cannot jump out of the loop problem and whether foreach will modify the original array
Gbase observation | how to protect the security of information system with frequent data leakage
pb9.0 insert ole control 错误的修复工具
MySQL数据库(2)
5、離散控制與連續控制
用户之声 | 冬去春来,静待花开 ——浅谈GBase 8a学习感悟
腾讯游戏客户端开发面试 (Unity + Cocos) 双重轰炸 社招6轮面试
Matlab method is good~
Grey correlation analysis link (portal) matlab
Urban land use distribution data / urban functional zoning distribution data / urban POI points of interest / vegetation type distribution
2022 safety officer-c certificate examination summary and safety officer-c certificate reexamination examination
Kafka-connect将Kafka数据同步到Mysql
QT -- package the program -- don't install qt- you can run it directly
2021 tea master (primary) examination materials and tea master (primary) simulation test questions
云原生应用开发之 gRPC 入门
DataWorks值班表
Capability contribution three solutions of gbase were selected into the "financial information innovation ecological laboratory - financial information innovation solutions (the first batch)"
Version 2.0 de tapdata, Open Source Live Data Platform est maintenant disponible
项目经理有必要考NPDP吗?我告诉你答案