![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
文章平均质量分 62
South__wind
ACMER
展开
-
hdu 1558 Segment set
线段判交+并查集: #include //#define min(x,y) (x < y ? x : y) //#define max(x,y) (x > y ? x : y) using namespace std; int fa[10000]; int ff(int y) { int t=fa[y]; while(t!=fa[t]) {原创 2012-09-01 20:53:30 · 399 阅读 · 0 评论 -
数据结构总结
常见的数据结构运用总结 考虑到Obsidian三个成员的擅长领域,这段时间都在做杂题,算是学习各种算法吧,趁现在休息的时间,而且大家马上要备战今年的比赛了,写写自己专攻方面的一些心得吧 扯开线段树、平衡树这些中高级的东西,先说说基础的数据结构 栈 算是代码量最小的数据结构?出栈进栈都只有一句话而已 常见用途: 消去一个序列中的相同元素(做法大家应该都知道了吧,见过很转载 2012-09-10 21:28:06 · 3442 阅读 · 0 评论 -
poj 3468 A Simple Problem with Integers
线段树入门的一个经典的题目,对特定区间的每一个值进行加减操作,并求指定区间的和。 #include struct node{ int l; int r; __int64 sum; __int64 add; }; node tree[300000]; int f[100002]; char oper[2]; int n,q; void build(int i,int l,原创 2012-08-27 20:38:54 · 254 阅读 · 0 评论 -
poj 2777 Count Color
区间染色,线段树。 #include #include struct node{ int l; int r; int col; }tree[400000]; int f[31]; char oper[2]; int len,t,o,a,b,d,ans; void build_tree(int i,int l,int r) { tree[i].l=l; tre原创 2012-08-27 20:01:42 · 245 阅读 · 0 评论 -
hdu 1199 Color the Ball
离散化,注意染色的顺序,一开始忽略了这个WA了。 #include using namespace std; struct Node{ int start; int end; }node[2000]; int a,b,st,en,n,num; char c; bool cmp(Node a,Node b) { return a.start<b.start;原创 2012-09-01 20:11:29 · 383 阅读 · 0 评论 -
HDU 1698 Just a Hook
线段树,主要是线段的更新。 #include #include int n,t,a,b,c,oper; struct node{ int l; int r; __int64 add; __int64 value; }tree[2000010]; void build_tree(int i,int l,int r) { tree[i].l=l; tr原创 2012-08-31 16:52:09 · 270 阅读 · 0 评论 -
poj 2528 Mayor's posters
#include #include using namespace std; #define MAX 40002 int a[MAX],b[MAX],flag[MAX],stl[MAX*250]; struct node{ int l,r,c; }; struct node tree[MAX*4]; #define Mid(idx) (tree[idx].l+tree[i原创 2012-08-30 15:03:05 · 607 阅读 · 0 评论 -
poj 2828 Buy Tickets
从后往前更新,tree[i].num表示区间的空位数。 Source Code Problem: 2828 User: yanxiaoli Memory: 8700K Time: 1625MS Language: C++ Result: Accepted Source Code #include struct node{ int l; int r; int num; }原创 2012-08-27 20:07:20 · 342 阅读 · 0 评论 -
hdu 1542 Atlantis
面积交是在面积并上修改的,一开始直接把fun里面的if( tree[i].cover >= 1)判断条件改成了 if( tree[i].cover >= 2 ),交了N遍WA,后来发现有种情况没有考虑,如果第一次覆盖,第二次覆盖是第一次的父节点。尝试标记父节点的时候,也标记子树,但发现会有冲突,后来参考了网上牛人的代码,在tree里面增加一个once用来记录只覆盖了一次的节点,然后对fun加以相应原创 2012-09-01 20:19:19 · 350 阅读 · 0 评论 -
hdu 1255
面积并: #include #include using namespace std; struct node { int l; int r; int cover; double once; double len; }; node tree[7000]; struct Line { double x; double y_d原创 2012-09-01 20:17:27 · 366 阅读 · 0 评论 -
hdu 1232 畅通工程
#include using namespace std; int u[1010],v[1010],p[1010]; int find(int x) { //return p[x] == x ? x : p[x] = find(p[x]); int t=p[x]; while(t!=p[t]) { t=p[t]; }原创 2012-09-01 20:14:34 · 295 阅读 · 0 评论 -
hdu 1213 How Many Tables
#include using namespace std; int father[1005]; int ff(int y) { int t=father[y]; while(t!=father[t]) { t=father[t]; } return t; } void result(int x,int y) { i原创 2012-09-01 20:13:35 · 317 阅读 · 0 评论 -
HDU 4107 Gungster
线段树,但是要优化,增加一个MIN,一个max,表示区间的最小值和最大值,当区间的的Max=p时直接加2*C,其实这个代码还是TLE了,实在不知道什么问题,后来直接交了几个别人过了的代码,包括偶像的,写的和我的都差不多。还是TLE,好吧,我好开心。。。。 我就当A了吧。。。 #include #include struct node{ int l; int r; __in原创 2012-08-31 16:24:25 · 427 阅读 · 0 评论 -
zoj 3573 Under Attack
更新的时候一定要确保更新到最后一排子节点,一开始忽略这个了,交了很多遍都是WA,所有的更新后在加一次更新,确保所有节点的add值为0.就可以了。 #include #include #include using namespace std; int n,q1,q2; int ma; struct node{ int l; int r; i原创 2012-08-31 00:57:02 · 351 阅读 · 0 评论 -
poj 3264 Balanced Lineup
线段树,求区间最大值与最小值 #include struct node { int l; int r; int mi; int ma; }tree[200000]; int a[200000]; int n,q,start,end; int max(int a,int b) { if(a>b) return a; return b;原创 2012-08-29 16:45:23 · 229 阅读 · 0 评论 -
hdu 1166 敌兵布阵
线段树的经典入门题: #include struct node { int l; int r; int val; }; node tree[1000002]; int a[50010]; char oper[9]; int n; void build(int i,int l,int r) { tree[i].l=l; tree[原创 2012-09-01 20:09:16 · 357 阅读 · 0 评论 -
Problem - 216B - Codeforces
题目链接http://codeforces.com/problemset/problem/216/B 题意:有一群人要踢足球,但是在这些人中有几对人存在敌对的关系,要求每个队的人数相等并且同一个队中不存在互为敌对关系的人,每个人最多只会讨厌两个人,如果a讨厌b,那么b也会讨厌a,问你至少有多少人不能参加比赛。 并查集的应用: 我们先把存在敌对关系的人之间连一条边,通过并查集把他们放在一个原创 2012-09-18 12:44:12 · 638 阅读 · 0 评论