当前位置:网站首页>Hill | insert sort
Hill | insert sort
2022-07-06 21:20:00 【2021CAT】
#include <bits/stdc++.h>
using namespace std;
const int in = 0.000001;
const double PI = 3.1415926535;
#define inf 0x3f3f3f;
typedef long long ll;
const int N = 1e5 + 10;
int q[N];
void Shell_sort (int a[], int n)
{
int d, i, j;
for (d = n / 2; d >= 1; d /= 2) // d Represents each increment , from n / 2 until d = 1 When d = 1 when This is also known as insertion sorting , This is done to optimize the insertion sort , Avoid when the number of inserts is small , It will cause multiple backward shifts .
for (i = d / 2; i < n; i ++)
{
if (a[i] < a[i - d]) // If a[i] Less than It corresponds to the previous hour of increment , Record a[i]
{
int x = a[i];
for (j = i - d; j >= 0 && x < a[j]; j -= d) // Find smaller ones in incremental order
{
a[j + d] = a[j]; // still a[i] < a[j] Move back to x Make room
}
a[j + d] = x; // Finally insert x
}
}
}
int main ()
{
int n;
cin >> n;
for (int i= 0; i < n; i ++) scanf ("%d", &q[i]);
Shell_sort (q, n);
for (int i = 0; i < n; i++)
i != n - 1 ? printf("%d ", q[i]) : printf("%d", q[i]);
return 0;
}
边栏推荐
- el-table表格——sortable排序 & 出现小数、%时排序错乱
- FZU 1686 龙之谜 重复覆盖
- Aike AI frontier promotion (7.6)
- KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
- Pat 1085 perfect sequence (25 points) perfect sequence
- 968 edit distance
- After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
- Interviewer: what is the internal implementation of ordered collection in redis?
- What's the best way to get TFS to output each project to its own directory?
- 3D人脸重建:从基础知识到识别/重建方法!
猜你喜欢
![[MySQL] trigger](/img/b5/6df17eb254bbdb0aba422d08f13046.png)
[MySQL] trigger

ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
![[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs](/img/66/4d94ae24e99599891636013ed734c5.png)
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs

966 minimum path sum

None of the strongest kings in the monitoring industry!

KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning

OneNote 深度评测:使用资源、插件、模版

【mysql】游标的基本使用

Why do job hopping take more than promotion?

Set up a time server
随机推荐
js通过数组内容来获取数组下标
启动嵌入式间:资源有限的系统启动
代理和反向代理
Notes - detailed steps of training, testing and verification of yolo-v4-tiny source code
20220211 failure - maximum amount of data supported by mongodb
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
string的底层实现
14年本科毕业,转行软件测试,薪资13.5K
Start the embedded room: system startup with limited resources
'class file has wrong version 52.0, should be 50.0' - class file has wrong version 52.0, should be 50.0
Reflection operation exercise
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
Deployment of external server area and dual machine hot standby of firewall Foundation
el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
Technology sharing | packet capturing analysis TCP protocol
3D人脸重建:从基础知识到识别/重建方法!
Torch Cookbook
[MySQL] basic use of cursor
Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"