上一页 1 2 3 4 5 6 7 8 9 10 ··· 28 下一页
摘要: 很容易想到的做法,对于每个询问(a,b),将a之前的人放入优先队列中,然后pop上b次将答案存下来,注意询问要先按照a的大小排好序。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; ... 阅读全文
posted @ 2015-09-14 09:42 hxy_has_been_used 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 先分块。对于查询,块内排好序二分,对于修改,直接暴力,注意需要维护原来的有序性,不断和块内相邻元素交换即可。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 const i... 阅读全文
posted @ 2015-09-05 22:10 hxy_has_been_used 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 又是基于连通性的问题,可以用并查集来解决,每个集合都维护一个优先队列,合并的时候按照优先队列的大小启发式合并即可。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int N = 10... 阅读全文
posted @ 2015-09-03 15:03 hxy_has_been_used 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 用线段树进行区间赋值,最后将每个小segment的颜色求出来,再扫一遍判断连续的段数即可。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 const int N = 8001; 7 int color[N... 阅读全文
posted @ 2015-09-03 10:04 hxy_has_been_used 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 此题关键在于维护点的连通性以及连通块的信息,容易想到并查集,但是并查集却不支持删边操作,于是考虑逆序处理,这样删边就变成了加边操作,每一个连通块的信息可以用stl中的multiset来维护,注意集合合并的时候要启发式合并(这里是按照集合的大小来合并,每次小的集合合并到大的集合里),不然会超时。 1... 阅读全文
posted @ 2015-09-02 08:48 hxy_has_been_used 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 查找比a大的第k小的元素其实就是查找第sum(a)+k小的元素,用不需要二分的树状数组就可以了。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 const int N = 100000; 7 int c[N]; 8 ... 阅读全文
posted @ 2015-09-01 16:29 hxy_has_been_used 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 题意:给定一个n个点n条边的无向图,判断是否存在哈密顿路径。思路:先用并查集判断图是否连通,然后从度数最小的点开始回溯,看是否能找到一条哈密顿路径。 1 #include 2 #include 3 #include 4 #include 5 using namespace std;... 阅读全文
posted @ 2015-08-31 09:21 hxy_has_been_used 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 用multiset模拟一下就可以了,需要注意的是erase(val)会将值等于val的全部删掉,而erase(iterator)只会删去该iterator指向的一个值。 1 #include 2 #include 3 #include 4 #include 5 using namespace... 阅读全文
posted @ 2015-08-29 09:56 hxy_has_been_used 阅读(217) 评论(1) 推荐(0) 编辑
摘要: 链表写法:新增加一个头结点来使插入操作统一。 1 #include 2 #include 3 #include 4 using namespace std; 5 6 const int N = 100001; 7 char text[N]; 8 char str[N]; 9 int next... 阅读全文
posted @ 2015-08-28 20:23 hxy_has_been_used 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 非常经典的差分约束系统的建模。求最小值需要转化为求最长路。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int INF = 99999999; 8 const int N = 50... 阅读全文
posted @ 2015-08-28 16:07 hxy_has_been_used 阅读(131) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 28 下一页