当前位置:网站首页>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;
}
边栏推荐
- js中,字符串和数组互转(一)——字符串转为数组的方法
- Three schemes of SVM to realize multi classification
- Nodejs tutorial let's create your first expressjs application with typescript
- C # use Oracle stored procedure to obtain result set instance
- Word bag model and TF-IDF
- 【论文解读】用于白内障分级/分类的机器学习技术
- Fastjson parses JSON strings (deserialized to list, map)
- El table table - sortable sorting & disordered sorting when decimal and% appear
- Huawei device command
- Swagger UI教程 API 文档神器
猜你喜欢

Swagger UI教程 API 文档神器

数据湖(八):Iceberg数据存储格式

SAP UI5 框架的 manifest.json

面试官:Redis中有序集合的内部实现方式是什么?
![[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

2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
![[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics](/img/2d/9a7e88fb774984d061538e3ad4a96b.png)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics

Absolute primes (C language)

ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer

This year, Jianzhi Tencent
随机推荐
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
This year, Jianzhi Tencent
Nodejs tutorial let's create your first expressjs application with typescript
防火墙基础之外网服务器区部署和双机热备
Technology sharing | packet capturing analysis TCP protocol
R language for text mining Part4 text classification
Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
OneNote 深度评测:使用资源、插件、模版
Web开发小妙招:巧用ThreadLocal规避层层传值
Summary of cross partition scheme
string的底层实现
OSPF多区域配置
Performance test process and plan
每个程序员必须掌握的常用英语词汇(建议收藏)
Fastjson parses JSON strings (deserialized to list, map)
OSPF multi zone configuration
SDL2来源分析7:演出(SDL_RenderPresent())
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
JS学习笔记-OO创建怀疑的对象
FZU 1686 龙之谜 重复覆盖