当前位置:网站首页>Acwing 787. Merge sort
Acwing 787. Merge sort
2022-06-13 09:25:00 【Age worry】
787. Merge sort
subject :
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n,a[N],m;
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=(l+r)>>1;
while(i<j){
do i++;while(a[i]<a[x]);
do j--;while(a[j]>a[x]);
if(i<j) swap(a[i],a[j]);
}
sort3(l,i);sort3(i+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;
}
边栏推荐
- 20211020 academician all drive system
- (bfs) acwing 844. Labyrinth
- LeetCode 201. 数字范围按位与
- Dpdk timer learning notes
- (bfs+GOOD) acwing 845. Eight digit
- Haproxy + keepalived for high availability load balancing of MySQL
- LeetCode 322. 零钱兑换
- LeetCode 6097. Match after replacing characters (Dictionary)
- CAS NO lock
- BGP Federation +community
猜你喜欢

C language: deep understanding of character functions and string functions (2)
![1-4 message passing interface [CSP authentication]](/img/db/aecda548693cdfb0e740bcf1a1c823.jpg)
1-4 message passing interface [CSP authentication]

C language: preprocessing in program environment

攻防世界PWN play 条件竞争漏洞的利用

Use typescript to complete simple snake eating function

Final principle

Library management system based on wechat applet Rar (thesis + source code)

(bfs) acwing 844. Labyrinth

Simulink variant model and variant subsystem usage

SQL ROW_ The number() function uses
随机推荐
IP address introduction
(state compression dp+ binary) acwing 91 Shortest Hamilton path
Yolov5 face learning notes
C language: data storage in memory
1-4 message passing interface [CSP authentication]
Final principle
20220524 how to install coppeliasim to disk D
Spectre record
I have summarized the knowledge points of JS [intermediate and advanced] for you
(bfs+GOOD) acwing 845. Eight digit
SpEL表达式 简单使用
LeetCode 5259. Calculate the total tax payable
JUC 字段更新器
LeetCode 1143. 最长公共子序列
Remember! Don't be too confident in writing code! Be sure to write some key log info output, or the problem will not be located.
删除软链接
Simple implementation of database link pool
C/S模型与P2P模型
LeetCode 72. 编辑距离
7-3 virus traceability (20 points)