当前位置:网站首页>Acwing785. quick sort (sort+ quick sort + merge sort)
Acwing785. quick sort (sort+ quick sort + merge sort)
2022-06-13 09:25:00 【Age worry】
785. Quick sort
subject 
Ideas : It was used sort(a,a+n)、 Quick line up 、 Three methods of merging and sorting
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n,a[N];
void sort1(){
sort(a,a+n);
}
void sort2(int l,int r){
if(l>=r) return;
int mid=(l+r)>>1;
//cout<<mid<<endl;
sort2(l,mid);
sort2(mid+1,r);
int t[N],k=0;
int i=l,j=mid+1;
for(;i<=mid && j<=r;){
if(a[i]<=a[j]) t[k++]=a[i++];
else t[k++]=a[j++];
}
while(i<=mid) t[k++]=a[i++];
while(j<=r) t[k++]=a[j++];
for(int i=0;i<k;i++){
a[l+i]=t[i];
}
}
void sort3(int l,int r){
if(l>=r) return ;
int i=l-1,j=r+1,x=a[(l+r)>>1];
while(i<j){
do i++;while(a[i]<x);
do j--;while(a[j]>x);
if(i<j) swap(a[i],a[j]);
}
sort3(l,j);sort3(j+1,r);
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
//sort1();
//sort2(0,n-1);
sort3(0,n-1);
for(int i=0;i<n;i++)
printf("%d ",a[i]);
return 0;
}
边栏推荐
- C language: deep understanding of character functions and string functions (2)
- 1-2 24:00 (20 points) [CSP certification true question]
- C language: deep understanding of character functions and string functions (1)
- 20211104 why are the traces of similar matrices the same
- C language: sanziqi
- How to build an aby framework and run an instance
- 攻防世界PWN play 条件竞争漏洞的利用
- Jenkins accédant à l'authentification de l'utilisateur openldap
- LeetCode 6098. Count the number of subarrays whose score is less than K (prefix and + binary search)
- Immutability of shared model
猜你喜欢

Routing - static routing

Longadder of the source code of JUC atomic accumulator

C language: deep understanding of character functions and string functions (1)

Solov2 source code analysis

Online debugging tool Arthas advanced

turtle库的使用数字时钟模拟时钟动态显示

20211104 why are the traces of similar matrices the same

全新BMW i3的操控,能符合对3系之名产品的期待吗?

Can the operation of the new BMW I3 meet the expectations of the famous products of the 3 series?

How Simulink adds modules to the library browser
随机推荐
Immutability of shared model
JUC原子整数
LeetCode 6096. Success logarithm of spells and potions (binary search)
C language: callback function
LeetCode 1143. Longest common subsequence
How Simulink adds modules to the library browser
Delete soft link
C language: summary of question brushing (1)
Spectre record
(dfs+ pruning + checkerboard problem +dood) acwing 843 N-queen problem
20211108 observable, controllable, stable and measurable
@Value不生效及extend/implement其他类无法注入bean的手动注入
BGP Federation +community
LeetCode 5270. 网格中的最小路径代价(动态规划)
删除软链接
Simple use of spiel expressions
Haproxy + keepalived for high availability load balancing of MySQL
Class loading overview
turtle库显示系统时间
1-4 message passing interface [CSP authentication]