上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 28 下一页
摘要: 题意:给定一棵树,求出树的直径以及个数。思路:dfs到结点u时,顺便统计出以u为lca的路径的最长距离和个数。故需要求出每个结点到叶子结点的最长距离以及个数。题目居然不给数据范围,不过实测n最大值为10000。 1 #include 2 #include 3 #include 4 using ... 阅读全文
posted @ 2015-08-21 12:55 hxy_has_been_used 阅读(120) 评论(0) 推荐(0)
摘要: 令dp[i][j][0]表示前i种物品花费最多j钱不买第i种物品可以获得的最大糖果数,dp[i][j][1]表示前i种物品花费最多j钱买第i种物品可以获得的最大糖果数,然后转移即可。第一维可以压缩掉。 1 #include 2 #include 3 #include 4 using names... 阅读全文
posted @ 2015-08-21 09:50 hxy_has_been_used 阅读(131) 评论(0) 推荐(0)
摘要: 块链:块内排序方便二分,然后进行类似于冒泡排序的更新即可。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 const int INF = 10000000... 阅读全文
posted @ 2015-08-20 19:49 hxy_has_been_used 阅读(252) 评论(0) 推荐(0)
摘要: 题意:给定一棵树,树上任意两点的距离为其路径上的边权的异或值,求距离等于某个值的点的对数。思路:这道题关键是要利用异或的性质。异或最基本的一个性质是和同一个数异或两次不发生改变。而对于这道题来说求出任意两点间的距离是不现实的,但是利用异或的性质,如果我们有了每个点到根的距离,就能间接得到任意两点间的... 阅读全文
posted @ 2015-08-20 18:40 hxy_has_been_used 阅读(891) 评论(0) 推荐(0)
摘要: 这道题算是非常基本的线段树了,采用线段树的原因是在线段树上查找到某个区间的复杂度是对数级别的。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 const int N = 200001; 7 int n, m; 8 9... 阅读全文
posted @ 2015-08-20 08:58 hxy_has_been_used 阅读(153) 评论(0) 推荐(0)
摘要: 树链剖分的入门题目,自己写了下感觉还是挺好写的,不过真的有点长...spoj 375 边有权值: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 const int INF = -999999999; 7 ... 阅读全文
posted @ 2015-08-19 16:55 hxy_has_been_used 阅读(180) 评论(0) 推荐(0)
摘要: 题目有提示内存限制,所以自然会想到用优先队列来维护前k大和前k小。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 typedef long long ll; 8 priority_queue, ... 阅读全文
posted @ 2015-08-19 10:50 hxy_has_been_used 阅读(268) 评论(0) 推荐(0)
摘要: 其实就是找一个最小的level k使得level 1到k的ant数量和不小于rank。树状数组: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 const int N = 100001; 7 int a[N]; 8 i... 阅读全文
posted @ 2015-08-18 20:07 hxy_has_been_used 阅读(113) 评论(0) 推荐(0)
摘要: 优雅的树状数组!人们发明了复杂度为logn的求解第k小的方法,常数小且代码量小,实在是用来求解本类题目的最佳方法,可惜的是我的Treap超时了......树状数组: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 con... 阅读全文
posted @ 2015-08-18 19:36 hxy_has_been_used 阅读(141) 评论(0) 推荐(0)
摘要: 没有插入和删除操作...所以还是很好写的,分块暴力就好了。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int N = 400; 8 const int M = 1... 阅读全文
posted @ 2015-08-17 16:33 hxy_has_been_used 阅读(241) 评论(0) 推荐(0)
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 28 下一页