随笔分类 - 数据结构
摘要:并查集显然要用到左偏树解决合并的问题这题体现了数据结构的强大啊!#include<stdio.h>#include <algorithm>using namespace std;const int MAXN = 100100;int father[MAXN];struct Monkey{ int l,r; int dis; int strong;}LTree[MAXN];int find(int x){ if(x != father[x]) father[x] = find(father[x]); return father[x];}int merge(int x,in
阅读全文
摘要:很CHUO的代码用的是单调队列还有更好的做法 以后补上#include <stdio.h>struct Queue{ int idx, val;}que[1000000];int a[1000000];int head, tail;int main(){ int n, k; scanf("%d%d",&n, &k); for(int i = 0; i < n; ++i){ scanf("%d",&a[i]); } // k 为1时候的特殊情况, 还有更好的做法.. if( k == 1 ){ for(int i
阅读全文
摘要:明显的优先队列用了STL,但是不全懂,自己写个堆估计悬... 有工具咱就用!#include <iostream>#include <queue>#include <vector>#include <stdio.h>using namespace std;const int MAXN = 60001;struct message{ char name[20]; int para,pri; int order; bool operator < (const message& m1)const { if(pri == m1.pri) r
阅读全文
摘要:/*RMQ问题——稀疏表算法状态转移方程dp[i,j]=min{dp[i,j-1],dp[i+2j-1,j-1]}*/#include <stdio.h>#include <math.h>#include <stdlib.h>const int MAXN = 50001;int max[MAXN][16],min[MAXN][16]; //2^16 = 65536int a[MAXN];int n, Q;inline int getMax(int a, int b){ return a > b ? a : b;}inline int getMin(in
阅读全文
摘要:单调队列 见http://www.cnblogs.com/lxf90/articles/2012016.html第一,原序列的坐标单调第二,原序列的值单调/*单调队列 */#include <stdio.h>using namespace std;const int MAXN = 100001;struct dqueue{ int val; int idx;}que[MAXN];int a[MAXN], cnt;int head, tail;int lefts;int main(){ int n; //cin >> n; scanf("%d",&am
阅读全文
摘要:/*哈希第一题啊..! 谢谢 http://www.cnblogs.com/Dario67/archive/2011/04/09/2010724.html 的博主这题投机取巧了,判断是否相等 直接排序 比较相等 混过去了 实际题目意思不是这样的 呵呵*/#include <stdio.h>#include <stdlib.h>#define M 99991 //大素数 这是怎么来的我还不清楚#define MAXN 100000struct flake{ int arm[6]; struct flake *next; //拉链法处理冲突 void init(){ nex
阅读全文
摘要:/*并查集!最后判断有几个父亲就是答案了*/#include <iostream>#include <set>using namespace std;struct G{ int left; int right; int up; int down;};const int MAXN = 50;int father[MAXN * MAXN]; int m,n;G g[11] = {{1,0,1,0},{0,1,1,0},{1,0,0,1},{0,1,0,1},{0,0,1,1},{1,1,0,0},{1,1,1,0},{1,0,1,1},{1,1,0,1},{0,1,1,1}
阅读全文
摘要://通过这题知道了可并堆这个东西.其实挺好理解的,体会到了//数据结构的强大啊!!!#include <stdio.h>#include <algorithm>using namespace std;const int MAXN = 100100;int father[MAXN];struct Monkey{ int l,r; int dis; int strong;}LTree[MAXN];int find(int x){ if(x != father[x]) father[x] = find(father[x]); return father[x];}int mer
阅读全文

浙公网安备 33010602011771号