一些有趣的教学视频
usaco视频讲解
https://blog.csdn.net/dllglvzhenfeng/article/details/123793428
递归
https://www.bilibili.com/video/BV1Nx411D712/?spm_id_from=333.337.search-card.all.click&vd_source=3113dafb4039f66ada07aa919944d0cf
dfs搜索树
https://blog.csdn.net/zgdlxs/article/details/122722493
dijkstra
https://www.bilibili.com/video/BV1QK411V7V4/?spm_id_from=333.788.videocard.0
归并排序
https://www.bilibili.com/video/BV1xW411Y7gY/?spm_id_from=trigger_reload
who is in the middle
#include<bits/stdc++.h> using namespace std; int a[100001],r[100001]; void mergesort(int s,int t) { int m,i,j,k; if(s==t) return ; m=(s+t)/2; mergesort(s,m); mergesort(m+1,t); i=s; j=m+1; k=s; while(i<=m&&j<=t) { if(a[i]<=a[j]) { r[k]=a[i]; i++; k++; } else { r[k]=a[j]; j++; k++; } } while(i<=m) { r[k]=a[i]; i++; k++; } while(j<=t) { r[k]=a[j]; j++; k++; } for(int i=s; i<=t; i++) a[i]=r[i]; } int main() { int n,i; scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); mergesort(1,n); printf("%d",a[(n+1)/2]); }
可用快速排序做到O(N)
#include<iostream> #include<cmath> #include<cstdlib> #include<utility> using namespace std; const int maxN=2e6+10; int n,a[maxN],k; int find(int l,int r,int k) { if(l==r) return a[l]; //int t=a[rand()%(r-l+1)+l]; int t=a[(l+r)/2]; int i=l,j=r; while(i<=j) { while(a[i]<t)i++; while(a[j]>t)j--; if(i<=j) { swap(a[i],a[j]); i++; j--; } } if(k<=j-l+1) return find(l,j,k); else if(k>i-l) return find(i,r,k-(i-l)); else return t; } int main() { cin>>n; k=(1+n)/2; for(int i=1; i<=n; ++i) cin>>a[i]; srand(10000); cout<<find(1,n,k)<<endl; return 0; }
https://blog.csdn.net/sinat_21902709/article/details/95738873
spacedesk