摘要: 优先队列或者说是堆得应用,最暴力的想法就是没输出一个最小值,更新,然后再排序,若用快排,时间效率为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 阅读全文
posted @ 2012-10-18 23:42 lishimin_come 阅读(115) 评论(0) 推荐(0) 编辑
摘要: #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) { ... 阅读全文
posted @ 2012-10-18 23:25 lishimin_come 阅读(123) 评论(0) 推荐(0) 编辑