#include<iostream>#include<cstdio>usingnamespace std;constint N =100005;int a[N];voidquick_sort(int a[],int l,int r){if(l >= r)return;int x = a[l + r >>1];int i = l -1, j = r +1;while(i < j){while(a[++i]< x);while(a[--j]> x);if(i < j)swap(a[i], a[j]);}quick_sort(a, l, j);quick_sort(a, j+1, r);}intmain(){int n;cin >> n;for(int i =0; i < n; i++){scanf("%d",&a[i]);}quick_sort(a,0, n -1);for(int i =0; i < n; i++){printf("%d ", a[i]);}return0;}
归并排序
#include<iostream>#include<cstdio>usingnamespace std;constint N =100005;int a[N], tmp[N];voidmerge_sort(int a[],int l,int r){if(l >= r)return;int mid = l + r >>1;merge_sort(a, l, mid);merge_sort(a, mid+1, r);int i = l, j = mid +1, k = i;while(i <= mid && j <= r){if(a[i]< a[j])tmp[k++]= a[i++];elsetmp[k++]= a[j++];}while(i <= mid)tmp[k++]= a[i++];while(j <= r)tmp[k++]= a[j++];for(int i = l; i <= r; i++){a[i]= tmp[i];}}intmain(){int n;cin >> n;for(int i =0; i < n; i++){scanf("%d",&a[i]);}merge_sort(a,0, n-1);for(int i =0; i < n; i++){printf("%d ", a[i]);}cout << endl;return0;}
最长上升子序列
#include<iostream>#include<algorithm>usingnamespace std;constint N =1010;int a[N], f[N];intmain(){int n;cin >> n;for(int i =1; i <= n; i++)cin >> a[i];for(int i =1; i <= n; i++){f[i]=1;for(int j =1; j < i; j++){if(a[j]< a[i])f[i]=max(f[i], f[j]+1);}}int res =0;for(int i =1; i <= n; i++){res =max(res, f[i]);}cout << res << endl;return0;}
最长公共子序列
#include<iostream>#include<algorithm>#include<cstring>constint N =1010;char a[N], b[N];int f[N][N];usingnamespace std;intmain(){int n, m;cin >> n >> m;cin >> a+1>> b+1;for(int i =1; i <= n; i++){for(int j =1; j <= m; j++){f[i][j]=max(f[i-1][j], f[i][j-1]);if(a[i]== b[j]){f[i][j]=max(f[i][j], f[i-1][j-1]+1);}}}cout << f[n][m]<< endl;return0;}
一、什么是 PHP? PHP(Hypertext Preprocessor,超文本预处理器)是一种广泛应用于 Web 开发的通用开源脚本语言。 PHP 主要用于服务器端编程,可以嵌入 HTML 中,与数据库进行交互,生成动态网页内容…