摘要: RMQ问题;采用游程编码;代码: 1 #include 2 #include 3 #include 4 #define maxn 100009 5 using namespace std; 6 7 int d[maxn][30],value[maxn],cnt[maxn],num[maxn],left[maxn],right[maxn]; 8 9 void RMQ_init(int n)10 {11 for(int i=1; ir)return 0;20 int k=0;21 while(1<<(k+1)<=r-l+1)k++;22 return max(d... 阅读全文
posted @ 2013-10-24 20:58 Yours1103 阅读(240) 评论(0) 推荐(0) 编辑
摘要: 树状数组,把他们的技能值作为轴;首先按照编号从小到大插入值,这样就可以得到,技能值比当前小的人数;然后按照编号从大到小再插一遍;代码: 1 #include 2 #include 3 #define maxn 20005 4 using namespace std; 5 6 int a[maxn],c[100010]; 7 int l[maxn],r[maxn]; 8 int lowbit(int x){return x&-x;} 9 void add(int x,int d){while(x0){ret+=c[x],x-=lowbit(x);}14 return ret;15 }1. 阅读全文
posted @ 2013-10-24 18:45 Yours1103 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 用两个优先队列来实现,因为队列只能从一头出去;所以维护一个数组,来标记这个队列的已经出列而另外一个队列没有出列的元素;到时候再把他们删了就行; 1 #include 2 #include 3 #include 4 #define maxn 1000009 5 using namespace std; 6 7 priority_queue,greater >gq; 8 priority_queue,less >lq; 9 int numg[maxn],numl[maxn];10 int main()11 {12 int n,x,k;13 while(scanf("%d&qu 阅读全文
posted @ 2013-10-24 17:28 Yours1103 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 链表的应用;le[i]表示第i个元素左边的那个元素的标号;ri[i]表示第i个元素右边的那个元素的标号;代码: 1 #include 2 #include 3 #define maxn 100009 4 using namespace std; 5 6 char s[maxn]; 7 int le[maxn],ri[maxn]; 8 9 int main()10 {11 while(gets(s+1)!=NULL)12 {13 le[0]=ri[0]=0;14 for(int i=1; s[i]; i++)15 {16 ... 阅读全文
posted @ 2013-10-24 16:43 Yours1103 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 带权值的并查集的应用;代码: 1 #include 2 #include 3 #include 4 #include 5 #define maxn 20005 6 using namespace std; 7 8 int f[maxn]; 9 int d[maxn];10 int t,n,x,y;11 char s[5];12 13 int find(int x)14 {15 if(f[x]!=x)16 {17 int r=find(f[x]);18 d[x]+=d[f[x]];19 return f[x]=r;20 }... 阅读全文
posted @ 2013-10-24 12:35 Yours1103 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 并查集的简单应用:代码: 1 #include 2 #define maxn 100005 3 using namespace std; 4 int f[maxn]; 5 int find(int x){return x==f[x]?x:f[x]=find(f[x]);} 6 int main() 7 { 8 int x,y; 9 while(scanf("%d",&x)!=EOF)10 {11 for(int i=0;i<maxn;i++)f[i]=i;12 int cnt=0;13 while(x!=-1)14 ... 阅读全文
posted @ 2013-10-24 10:50 Yours1103 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 多路并归问题:代码: 1 #include 2 #include 3 #include 4 #define maxn 760 5 using namespace std; 6 7 struct node 8 { 9 int s,b;10 node(int s,int b):s(s),b(b) {}11 bool operatort.s;14 }15 };16 17 void merge(int *a,int *b,int *c,int n)18 {19 priority_queueq;20 for(int i=0; i<n; i++)21 ... 阅读全文
posted @ 2013-10-24 10:13 Yours1103 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 简单的优先队列的应用;代码: 1 #include 2 #include 3 using namespace std; 4 5 struct node 6 { 7 int num; 8 int ti; 9 int period;10 bool operatort.num;13 return ti>t.ti;14 }15 };16 priority_queueq;17 char s[20];18 int main()19 {20 int m;21 node a;22 while(scanf("%s",&s)&&s[... 阅读全文
posted @ 2013-10-24 09:49 Yours1103 阅读(151) 评论(0) 推荐(0) 编辑