[//]: # 6_17号,第一次打卡,(目标10天之内完成基础课程,请大家监督)
题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include <iostream>
using namespace std;
const int N = 10000005;
int a[N];
void merge(int a[], int left, int right)
{
int b[right - left + 1];
int mid = (left + right)/2;
int l = left;
int r = mid + 1;
int index = 0;
while(l <= mid && r <= right)
{
if(a[l] < a[r])
{
b[index++] = a[l++];
}
else
b[index++] = a[r++];
}
while(l <= mid)
b[index++] = a[l++];
while(r <= right)
b[index++] = a[r++];
for(int i = left; i <= right; i++)
{
a[i] = b[i - left];
}
}
void MergeSort(int a[], int left, int right)
{
if(left >= right)
{
return;
}
int mid = (left + right) / 2;
MergeSort(a,left,mid);
MergeSort(a,mid+1,right);
merge(a,left, right);
}
int main()
{
int n = 0;
int k = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
MergeSort(a,0,n-1);
for(int i = 0; i < n; i++)
{
cout << a[i] << ' ';
}
cout << endl;
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla