
数据结构
sepNINE
it is written
展开
-
poj 1442 Black Box 数据结构(线段树)
题意:给一列数A[1],A[2],原创 2014-10-18 21:26:36 · 675 阅读 · 0 评论 -
poj 2886 Who Gets the Most Candies? 线段树动态求第k大的数
题意:n个小孩站一圈,每个小孩拿一个数字,从第k个孩子开始出局,然后下一个出局的孩子是刚刚出局的孩子之前或之后第v个(刚刚出局的孩子的数字是+v则之后v个,-v则之前v个),这样所有孩子终将出局,第p个出局的孩子得f(p)分,f(p)定义为p的因子个数。求分数最高的孩子。分析:设顺时针为正方向,关键是模拟出每次出局的孩子是剩下的孩子中的正方向的第几个,设当前要出局的是第k个,然后要求出原创 2015-04-15 23:49:45 · 612 阅读 · 0 评论 -
poj 3074 Sudoku dlx解数独
分析:dlx是从数据结构角度优化01矩阵精确覆盖和重复覆盖的数据结构,它用十字链表只存贮矩阵中的非0元,而01矩阵精确覆盖dfs过程中矩阵会越来越稀疏而且每次恢复现场会浪费大量时间,dlx恰好能解决这两个问题。本题关键是将数独问题转化为01矩阵精确覆盖。数独转化为精确覆盖问题的方法还是参照Knuth的论文,如果读取到一个格子是空的,那么加9行,分别表示这个格子填1到9这9个数字,如果读取到的格原创 2015-04-27 15:25:32 · 1508 阅读 · 0 评论 -
poj 1084 Square Destroyer dlx解重复覆盖
分析:将问题转化为重复覆盖问题,DancingLink解决。代码://poj 1084//sep9#include using namespace std;const int maxN=10024;const int maxL=128;int L[maxN],R[maxN],U[maxN],D[maxN];int C[maxN],H[maxN];int S[maxN],原创 2015-05-02 22:45:24 · 1499 阅读 · 0 评论 -
poj 3076 Sudoku dlx解数独
16*16的数独,类似poj 3074.//poj 3076//sep9#include #include #define INT_MAX 2147483647using namespace std;const int col_num=16*16*4;const int row_num=16*16*16+10; const int head=0;const int MAX原创 2015-04-27 19:46:55 · 917 阅读 · 0 评论 -
poj 2991 Crane 线段树lazy_tag
//poj 2991//sep9#include #include using namespace std;const int MAXN=100024;const double PI=acos(-1.0);double sumx[MAXN*4],sumy[MAXN*4];int angle[MAXN],alpha[MAXN*4];void push_up(int k){ s原创 2015-10-19 15:39:16 · 422 阅读 · 0 评论 -
poj 2763 Housewife Wind 动态求树上两点之间距离
题意:给一棵n分析:首先用dfs将数序列化,然后用rmq求lca,用树状数组求树上两点之间的距离和更新边。 代码://poj 2763//sep9#include #include using namespace std;const int MAXN=100024;const int LOG_MAXN=20;struct EDGE{ int idx,v,w,nx原创 2015-10-13 14:52:08 · 644 阅读 · 2 评论 -
poj 2482 Stars in Your Window 线段树+离散化
//poj 2482//sep9#include #include using namespace std;typedef __int64 INT;typedef pair,pair > SEG;//(x,cs),(y1,y2)const int MAXN=10000;INT n,W,H;INT xs[MAXN+10],ys[MAXN+10];INT cs[MAXN+10];原创 2016-01-11 12:30:11 · 544 阅读 · 0 评论 -
poj 1177 区间树求矩形周长并
题意: 在平面上给若干矩形,求它们的周长并。分析:用区间树维护x轴上区间的一些覆盖属性。区间树维护的是一些区间的性质,构造为build(l,mid),build(mid,r),线段树维护的是一些点的性质,构造为build(l,mid),build(mid+1,r)。区间树经常被视为线段树,但个人认为因为点线有所却分,故考虑问题时还是把他们区别对待比较好,虽然它们的核心思想如原创 2016-02-27 15:50:10 · 813 阅读 · 0 评论 -
poj 3225 Help with Intervals 线段树lazy-tag求解区间运算
//poj 3225#include using namespace std;#define lx (x<<1)#define rx ((x<<1)|1)#define MID ((l+r)>>1)const int MAXN=140000;int cover[MAXN<<2];int XOR[MAXN<<2];bool vis[MAXN+10];void FXOR(int原创 2016-02-29 02:30:46 · 528 阅读 · 0 评论 -
poj 1521 Entropy 并查集+优先队列实现哈夫曼编码
//poj 1521//sep9#include #include using namespace std;typedef pair pii;char s[10024];int height[512];int cnt[512];int f[512];int find(int u){ return f[u]==u?f[u]:f[u]=find(f[u]);}void so原创 2016-05-16 07:17:37 · 735 阅读 · 0 评论 -
poj 3007 Organize Your Train part II 哈希判重
//poj 3007//sep9#include #include using namespace std;const int MAXN=1024;const int HASHLEN=1000024;int n,cnt;char s[MAXN],s1[MAXN],s2[MAXN],s3[MAXN],s4[MAXN];struct HashNode{ char str[MAXN]原创 2016-09-24 00:12:22 · 1052 阅读 · 0 评论 -
poj 1737 Connected Graph 组合递推计数+高精度
题意:求n个点的无向联通图有多少个。分析:递推计数,需要高精度,我这个模版里的乘法利用了m位数乘n位数不超过m+n位数的原理采用了延迟进位技术,无需设置进位,乘法代码不超过10行。代码://poj 1737//sep9#include using namespace std;struct H { int a[100],len; H(){me原创 2017-01-19 10:10:07 · 612 阅读 · 0 评论 -
poj 3044 City Skyline 单调栈
//poj 3044//sep9#include #include using namespace std;const int MAXN=80000;int x,y[MAXN];int main(){ int n,w; while(scanf("%d%d",&n,&w)==2){ for(int i=0;i<n;++i){ scanf("%d%d",&x,&y[i]原创 2017-02-28 17:03:15 · 785 阅读 · 0 评论 -
poj 1769 Minimizing maximizer 单点更新线段树
//poj 1769//sep9#include using namespace std;const int MAXN=100012;const int MAXX=9999999;int n,m;int minv[MAXN*4];void build(int l,int r,int k) { minv[k]=MAXX; if(l==r) ret原创 2017-08-30 21:15:25 · 1154 阅读 · 0 评论 -
poj 3580 SuperMemo splay树模板题
splay树 模板题原创 2015-04-24 01:07:25 · 1240 阅读 · 0 评论 -
poj 4047 Garden 线段树lazy标记与成段更新
线段树lazy标记技术副题详解原创 2015-03-30 20:29:42 · 728 阅读 · 0 评论 -
poj 2750 Potted Flower 数据结构(线段树)
题意:给一个hui大小为n的数组,原创 2014-11-04 22:23:39 · 663 阅读 · 0 评论 -
poj 2513 Colored Sticks 字典树
题意:给一堆小棒,每跟小棒上有两种颜色,颜色相同的两端可以连起来,问所有小棒是否可以练成一条线。分析:无向图是否存在欧拉路径问题,这题主要是与输入做斗争,输入的字符串用map水的话会超时,只能老老实实写字典树。代码://poj 2513//sepNINE#include #include using namespace std;const int maxN=5000原创 2014-11-28 18:16:03 · 545 阅读 · 0 评论 -
poj 2464 Brownie Points II 树状数组
题意:给Stan个点,玩家Stan先经过某个点画一条竖线,玩家Ollie再经过这条线上的某一点画一条竖线,这样将整个区域分为4个区域,左上和右下里的点是Stan的得分,左下和右上是Ollie的得分,问Stan最多能得多少分和在保证Stan的最高分的情况下Ollie能得的最高分是多少.注意Stan选择一条竖线后Ollie要站在有利于自己的情况下考虑。分析:这题的本质是在足够快的时间内对每原创 2014-11-27 22:24:46 · 610 阅读 · 0 评论 -
poj 2010 Moo University - Financial Aid 大顶堆维护最小和
题意:有c有牛,从中选(n-1)/2头,使他们的得分中位数最大且需要的资金援助和不超过f.分析:堆的运用大顶堆维护最小和。代码://poj 2010//sep9#include #include #include using namespace std;const int maxN=100024;int dpl[maxN],dpr[maxN];priority原创 2015-01-08 11:45:59 · 897 阅读 · 0 评论 -
poj 2756 Autumn is a Genius 高精度加减
题意:求a+b。-10^50000分析:题目描述很猥琐,其实要用高精度的,用高精度加减模板。代码://poj 2756//sep9#include using namespace std;const int maxN=60000;char A[maxN],B[maxN];int L,flag1,flag2,flag3,a[maxN],b[maxN],c[maxN];原创 2015-01-29 14:53:44 · 1297 阅读 · 0 评论 -
poj 3616 Milking Time dp+树状数组
数状数组哭了:我本来是搞区间和的,怎么被用来搞rmq了T^T。。。原创 2014-12-22 13:47:26 · 693 阅读 · 0 评论 -
poj 2442 Sequence 优先队列的运用
题意:给m行,每行n个数,从每行取一个数计算和,求前n小的和。分析: 优先队列的运用,主要是make_heap,pop_heap,push_heap三个STL函数的用法。代码://poj 2442 //sep9#include #include using namespace std;const int maxN=2048;int a[maxN],b[m原创 2015-01-13 23:34:25 · 956 阅读 · 0 评论 -
poj 3481 Double Queue STL中map的运用
题意:维护一个集合,操作有1:加入一个元素,2:删除最大元素,3:删除最小元素。分析:map本质是个容器,且具有第一个关键字有序的性质,所以用它来水水就好啦~代码://poj 3481//sep9#include #include using namespace std;map mymap;map::iterator iter; int main(){ int原创 2015-01-14 22:46:46 · 1051 阅读 · 0 评论 -
poj 2761 Feed the dogs 划分树
题意:给长度为n的数组和m个区间,求这m个区间中第k小的数。分析:数组静态,区间和k动态,划分树的定义题,上模板。代码://poj 2761//sep9#include #include using namespace std;#define MID(a,b) (a+((b-a)>>1))const int maxN=100010;struct Node{ i原创 2014-12-25 23:22:50 · 623 阅读 · 0 评论 -
poj 2785 4 Values whose Sum is 0 哈希
poj 2785 4 Values whose Sum is 0 哈希入门题原创 2014-12-26 14:17:07 · 669 阅读 · 0 评论 -
poj 1204 Word Puzzles 静态trie树解决多模式串匹配问题
题意:给一个二维字符数组和w个模式串,求这w个模式串在二维字符数组的位置。分析:静态trie树。代码://poj 1204//sep9#include using namespace std;const int maxN=1024;const int maxM=270*maxN;char str[maxN][maxN];char s[maxN];int vis[原创 2015-01-15 11:35:14 · 1045 阅读 · 0 评论 -
poj 3378 Crazy Thairs 树状数组+高精度+dp
题意:给一个长为n的序列,求里面长度为5的上升子序列有多少个。分析:树状数组c[i][j]表示以i结尾长度为j的序列数量,要用高精度。代码://poj 3378//sep9#include #include using namespace std; const int maxN=50012; pair x[maxN];int v[maxN];int原创 2014-12-27 23:08:44 · 813 阅读 · 0 评论 -
poj 1195 Mobile phones 二维树状数组
题意:动态单点更新和查询区域和。分析:裸的二维树状数组,不过我用一维的暴力3600+ms过了,罪过。。之后也附上别人二维树状数组的正确做法吧。代码:一维暴力解法://poj 1195//sep9#include using namespace std;const int maxN=1024+10; struct BIT { int c[maxN]原创 2015-01-22 17:14:33 · 563 阅读 · 0 评论 -
poj 2526 Center of symmetry 哈希查找
题意:给n个不同的点,问是否存在一个点使得这n个点关于它两两对称。分析:首先确定这个对称中心的坐标,然后对每个点哈希查找它的对称点。代码://poj 2526//sep9#include using namespace std;const int maxN=10024;const int hashlen=1000023;const int mod=40013;st原创 2015-03-29 19:15:58 · 707 阅读 · 0 评论 -
poj 3735 Training little cats 矩阵的幂
题意:给一个长度为n的数列,初始化为0,有3种操作:1)将某个元素增加1;2)将某个元素置0;3)交换两个元素。现在给出包含k个操作的一组操作,求m组操作后数列的状态。分析:找出初始矩阵A和转移矩阵T后就可以用快速幂计算了。代码://poj 3735//sep9#include using namespace std;typedef long long LL;cons原创 2015-03-22 13:05:58 · 698 阅读 · 0 评论 -
poj 3263 Tallest Cow 差分数列或线段树解区间修改
#include <iostream>#include <map>using namespace std;const int max_n = 10024;int c[max_n], d[max_n];map<pair<int, int>, bool> existed;int main() { int N, I, H, R; ...原创 2019-06-21 23:05:02 · 292 阅读 · 0 评论