当前位置:网站首页>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;
}
边栏推荐
- In JS, string and array are converted to each other (II) -- the method of converting array into string
- 2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
- Is it profitable to host an Olympic Games?
- Study notes of grain Mall - phase I: Project Introduction
- 20220211 failure - maximum amount of data supported by mongodb
- Ravendb starts -- document metadata
- PHP saves session data to MySQL database
- This year, Jianzhi Tencent
- 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
- 分糖果
猜你喜欢
Is it profitable to host an Olympic Games?
Interviewer: what is the internal implementation of ordered collection in redis?
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
【mysql】触发器
Aiko ai Frontier promotion (7.6)
966 minimum path sum
Aike AI frontier promotion (7.6)
Summary of cross partition scheme
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
防火墙基础之外网服务器区部署和双机热备
随机推荐
b站视频链接快速获取
c#使用oracle存储过程获取结果集实例
OneNote 深度评测:使用资源、插件、模版
首批入选!腾讯安全天御风控获信通院业务安全能力认证
js通过数组内容来获取数组下标
基于深度学习的参考帧生成
R语言做文本挖掘 Part4文本分类
WEB功能测试说明
Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
Yyds dry inventory run kubeedge official example_ Counter demo counter
代理和反向代理
038. (2.7) less anxiety
How do I remove duplicates from the list- How to remove duplicates from a list?
如何实现常见框架
Pat 1078 hashing (25 points) ⼆ times ⽅ exploration method
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
Deployment of external server area and dual machine hot standby of firewall Foundation
Why does MySQL index fail? When do I use indexes?