2013年7月14日

摘要: http://acm.timus.ru/problem.aspx?space=1&num=1416又是次小生成树啊。 1 #include 2 #include 3 #include 4 using namespace std; 5 #define maxn 505 6 #define inf (int)(1lowcost[j]){28 min=lowcost[j];29 k=j;30 }31 if(min==inf)32 flag=1;33 ans+=min;34 ... 阅读全文
posted @ 2013-07-14 21:26 kim888168 阅读(191) 评论(0) 推荐(0) 编辑

2013年7月13日

摘要: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=1541&mosmsg=Submission+received+with+ID+12044428题意:给出一个图,求出次小生成树。。。 1 #include 2 #include 3 #include 4 using namespace std; 5 #define maxn 102 6 #define inf (int)(1lowcost[j]) 阅读全文
posted @ 2013-07-13 17:01 kim888168 阅读(185) 评论(0) 推荐(0) 编辑

2013年6月29日

摘要: http://acm.uestc.edu.cn/problem.php?pid=1558 1 #include 2 #include 3 #include 4 using namespace std; 5 #define lson l,m,rt>1; 32 build(lson); 33 build(rson); 34 } 35 int binsearch1(int l,int r,int num,int &pos) 36 { 37 if(l>r) 38 return pos; 39 int m=(l+r)>>1; 40 if(n... 阅读全文
posted @ 2013-06-29 17:35 kim888168 阅读(174) 评论(0) 推荐(0) 编辑

2013年6月26日

摘要: 题意就不多说了,其实就是一个dp优化题目。 1 #include 2 #include 3 using namespace std; 4 #define lson l,m,rt>1; 17 build(lson); 18 build(rson); 19 } 20 int binsearch1(int l,int r,int num,int &pos) 21 { 22 if(l>r) 23 return pos; 24 int m=(l+r)>>1; 25 if(sorted[m]>=num){ 26 pos=m; 27... 阅读全文
posted @ 2013-06-26 21:14 kim888168 阅读(140) 评论(0) 推荐(0) 编辑

2013年5月29日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4366 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 #define lson l,m,rt<<1 6 #define rson m+1,r,rt<<1|1 7 #define maxn 50005 8 struct node{ 9 int num,id; 10 }setree[maxn<<2]; 11 st 阅读全文
posted @ 2013-05-29 09:29 kim888168 阅读(115) 评论(0) 推荐(0) 编辑

2013年5月26日

摘要: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2412先dp出每个时刻的所能获得的最大分值,线段树维护每个时刻的最优值,对于i时刻,可以先求出区间1到i-m-1的最大值,然后更新i。 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 #define lson l,m,rt<<1 6 #define rson m+1,r 阅读全文
posted @ 2013-05-26 23:29 kim888168 阅读(223) 评论(0) 推荐(0) 编辑

2013年5月25日

摘要: 1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 #define lson l,m,rt+1 5 #define rson m+1,r,rt+1 6 #define maxn 100005 7 struct{ 8 char s[10]; 9 int l,r,num; 10 }mes[maxn<<2]; 11 struct node{ 12 int num,val; 13 }setree[18][maxn]; 14 int sorted[maxn]; 15 void ... 阅读全文
posted @ 2013-05-25 11:48 kim888168 阅读(129) 评论(0) 推荐(0) 编辑

2013年5月16日

摘要: 题意就是给你一颗树。初始时每个节点的值都为0,现在有两种操作,‘o’操作是将以节点i为根的子树的每个节点取反,即0变1,1变0.‘q’操作是求以节点i为根的子树中1的个数。方法主要是给每个节点分配一个区间,是这个区间的节点都是它的子节点。然后就是线段树的经典操作啦。 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 #define lson l,m,rt<<1 6 #define rson m+1,r,rt<< 阅读全文
posted @ 2013-05-16 20:57 kim888168 阅读(105) 评论(0) 推荐(0) 编辑
 
摘要: 这题很容易想到O(n^2)的做法,但这样肯定是要超时的,对于第i个box,可以用线段树在logn的时间内找出小于mes[i].h且能拿到最多金子的box。类型:线段树优化Dp。 1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 #define lson l,m,rt<<1 5 #define rson m+1,r,rt<<1|1 6 #define maxn 100005 7 struct { 8 int max; 9 }setree[maxn<<2 阅读全文
posted @ 2013-05-16 11:03 kim888168 阅读(132) 评论(0) 推荐(0) 编辑

2013年5月15日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4267题意就不多说了,由于需要更新的点都是离散的,按照普通线段树更新肯定是会超时的,但1 <= k <= 10,所以我们可以把k=1时,建立一颗线段树,k=2时建立对应模为0和1的两颗线段树,其他以此类推,共建立55颗线段树,这样更新时只要找到符合条件的线段树和区间就能和普通线段树一样更新了,而查询时需要找k=1,k=2,。。。k=10的相应的线段树,共查询10颗线段树,就能得到答案了。 1 #include <cstdio> 2 #include <algorithm> 阅读全文
posted @ 2013-05-15 15:16 kim888168 阅读(152) 评论(0) 推荐(0) 编辑