摘要:
优先队列或者说是堆得应用,最暴力的想法就是没输出一个最小值,更新,然后再排序,若用快排,时间效率为O(knlgn),但不需要对所有的排次序,所以就用到最小堆#include <iostream>
#include <queue>
#include <string>
using namespace std;
typedef struct node
{ int n,p,r;
}ar;
bool operator<(ar a,ar b)
{ if(a.p==b.p) return a.n>b.n; else return a.p>b.p;
}
p 阅读全文
摘要:
#include <iostream>
using namespace std;
const int maxn=8000+10;
struct node
{ int l,r,len;
}tree[maxn*3];
void Create(int p,int l,int r)
{ tree[p].l=l; tree[p].r=r; tree[p].len=r-l+1; if(l!=r) { int mid=(l+r)/2; Create(2*p+1,l,mid); Create(2*p+2,mid+1,r); }
}
int find(int p,int am)
{ ... 阅读全文