摘要: http://blog.csdn.net/lyy289065406/article/details/6642573转载请注明出处:優YoUhttp://blog.csdn.net/lyy289065406/article/details/6642573最近AC题:2528更新时间:2011.09.22 已AC题数:146初级题已在2011.06.30全部完成部分解题报告添加新内容,除了原有的“大致题意”和“解题思路”外,新增“Source修正”,因为原Source较模糊,这是为了帮助某些狂WA的同学找到测试数据库,但是我不希望大家利用测试数据打表刷题PS:部分题目的评论中也有给出了测试数据,未 阅读全文
posted @ 2012-10-17 12:20 Missa 阅读(1317) 评论(2) 推荐(0) 编辑
摘要: 1 /* 2 线段树 + hash: 3 首先我们可以知道A序列是1~n的排列,那么我们可以先在B序列中把1~n的排列找出来,看其相对位置是否与A相同(hash可做),相同即表明存在一个d满足条件。 4 以此类推,我们接下来可以把B中 2~ n + 1的排列找出来,如果其每位-1后相对顺序还是与A序列一致,即存在d-1也满足。。。 5 线段树中保存一个长度为n的序列的hash。具体看代码 6 */ 7 #include 8 9 using namespace std;10 11 #define lson l, m ,rt> 1;31 if (p =... 阅读全文
posted @ 2013-11-28 14:52 Missa 阅读(666) 评论(0) 推荐(0) 编辑
摘要: 题目:给出一些询问,[l,r]的和为s,问有多少个是错的 1 //并查集 ,,sum[a]表示a与父亲这条路径上的和 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 const int maxn = 2e5 + 5;10 int fa[maxn], sum[maxn];11 int n, m, l, r, s;12 int findFa(int x){13 if (x != fa[x]){14 int t = fa[x];15 fa[x] = f... 阅读全文
posted @ 2013-11-10 13:57 Missa 阅读(444) 评论(0) 推荐(0) 编辑
摘要: 题目:给出一个序列,找出一个最长的子序列,相邻的两个数的差在d以内。 1 /* 2 线段树优化dp 3 dp[i]表示前i个数的最长为多少,则dp[i]=max(dp[j]+1) abs(a[i]-a[j]) 8 #include 9 #include 10 #include 11 #include 12 13 using namespace std;14 #define lson l,m,rt> 1;30 if (pos = r){36 return sum[rt];37 }38 int m = (l + r) >> 1;39 int ret... 阅读全文
posted @ 2013-11-10 13:10 Missa 阅读(671) 评论(0) 推荐(0) 编辑
摘要: 1 //离散化 + 扫描线 + 线段树 2 //这个线段树跟平常不太一样的地方在于记录了区间两个信息,len[i]表示颜色为i的被覆盖的长度为len[i], num[i]表示颜色i 『完全』覆盖了该区间几层。len[i]起传递儿子与父亲的关系,而num[i]不起传递作用,只是单纯的表示被覆盖的区间。 3 //然后就是pushUp函数,必须在update到底层后即更新num[]和len,然后把len传上去。 4 //离散化后由于求的是面积,所以我是把每条长度为1的线段当做一个点, 即把左端点表示此段长度。而不是把点当成点。 5 #include 6 #include 7 #i... 阅读全文
posted @ 2013-11-09 13:32 Missa 阅读(361) 评论(0) 推荐(0) 编辑
摘要: 题目:有一个圈,可以从某个位置取球,给出原有的顺序,有三种操作,左旋一次,右旋一次,取球,要求按顺序取球,问需要操作多少次显然操作是确定的,每次将目标球旋转过来,找出左旋和右旋操作少的,然后取球。每次旋转后相对距离不变,每次记录某个区间删掉了多少,就可以查询了。 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 #define lson l, m, rt> 1;17 if (p R) return 0;22 if (L = r){23 return sum[r... 阅读全文
posted @ 2013-11-05 16:00 Missa 阅读(341) 评论(0) 推荐(0) 编辑
摘要: http://acm.hfut.edu.cn/OnlineJudge/中文题。区间线段树,需要剪枝。n的大小有问题。 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 #define ls rt> 1;30 build(lson);31 build(rson);32 seg[rt].maxv = max(seg[ls].maxv, seg[rs].maxv);33 seg[rt].minv = min(seg[ls].minv, seg[rs].minv);34... 阅读全文
posted @ 2013-10-10 17:13 Missa 阅读(410) 评论(0) 推荐(0) 编辑
摘要: 题意:有一个序列a[],mex(L, R)表示区间a在区间[L, R]上第一个没出现的最小非负整数,对于序列a[],求所有的mex(L, R)的和(1 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 #define ls rt> 1; 41 build(lson); 42 build(rson); 43 pushUp(rt); 44 } 45 int find(int key, int l, int r, int rt){//找到第一个mex大于a[i... 阅读全文
posted @ 2013-10-10 15:51 Missa 阅读(1011) 评论(0) 推荐(0) 编辑
摘要: http://www.spoj.com/problems/COT/树上第k小元素LCA + 可持久化线段树每个新的版本都是由其父亲版本转化而来。 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 const int maxn = 1e5 + 5; 9 const int maxd = 20; 10 struct Edge{ 11 int v, next; 12 }p[maxn = 0; --i){ 33 if (f[u][i] != f[v][i... 阅读全文
posted @ 2013-09-24 10:51 Missa 阅读(591) 评论(0) 推荐(0) 编辑
摘要: bubble_sort:将序列划分为无序区跟有序区,不断通过交换较大的元素至无序区尾完成排序。 1 #include 2 #include 3 4 using namespace std; 5 6 void bubble_sort(int arr[], int n){ 7 for (int i = 0; i 2 #include 3 #include 4 5 using namespace std; 6 #define lson(x) (x a[Max]) Max = ls;19 if (rs a[Max]) Max = rs;20 if (Max ... 阅读全文
posted @ 2013-08-26 22:05 Missa 阅读(384) 评论(0) 推荐(0) 编辑
摘要: 1 /*若原图的基图不连通, 2 或者存在某个点的入度或出度为 0 则无解。 3 统计所有点的入度出度之差 Di, 对于 Di > 0 的点, 4 加边(s, i, Di, 0); 对于 Di 0 的边(i, j),在原图中复制fij 份,这样原图便成为欧拉图,求一次欧拉回路即可。 9 */ 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 17 using namespace std; 18 19 const int maxn = 1e2 + 5; 20 cons... 阅读全文
posted @ 2013-08-21 22:22 Missa 阅读(665) 评论(0) 推荐(0) 编辑
摘要: http://acm.hit.edu.cn/hoj/problem/view?id=2715将每个格子 i 拆成两个点 i’, i’’并加边(i’, i’’, 1, -Vi), (i’, i’’, ∞, 0), (s, i’, ∞, 0); 控制只有一次能取到宝物。对相邻的四个格子 j, Hi > Hj 则加边(i’’, j’, ∞, 0);若格子 i 在边界上则加边(i’’, t, ∞, 0)。限制增广次数小于等于 K 求最小费用流即可。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include ... 阅读全文
posted @ 2013-08-18 17:40 Missa 阅读(332) 评论(0) 推荐(0) 编辑
摘要: http://acm.hit.edu.cn/hoj/problem/view?id=25431.将原图中的每条边(u, v)拆成两条:(u, v, Ci, 0), (u, v, ∞, Ei)2.购买的每个石头的费用P加一条 (S, 1, inf, P)的边。3.总的能够花费的费用C可以在我们求最小费用路的时候判断。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 typedef long long LL; 10 const i... 阅读全文
posted @ 2013-08-18 12:39 Missa 阅读(293) 评论(0) 推荐(0) 编辑
摘要: // 给定一个有向图,必须用若干个环来覆盖整个图,要求这些覆盖的环的权值最小。思路:原图每个点u 拆为u 和 u' ,从源点引容量为 1 费用为 0 的边到u ,从 u' 引相同性质的边到汇点,若原图中存在 (u, v) ,则从u 引容量为 1 费用为 c(u, v) 的边到 v' 。其实这里的源模拟的是出度,汇模拟的是入度,因为环中每个点的出度等于入度等于 1 ,那么如果最大流不等于顶点数 n ,则无解;否则,答案就是最小费用。 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 阅读全文
posted @ 2013-08-18 10:16 Missa 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 注意题目中 边的容量 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 const int maxn = 110; 9 const int maxm = 25000; 10 const int inf = 0x3f3f3f3f; 11 const int ww[5] = {1, 3, 5, 7, 9}; 12 13 struct MCMF 14 { 15 struct Edge 16 { 17 int v, c, w, next; 18 }p[maxm... 阅读全文
posted @ 2013-08-17 09:24 Missa 阅读(287) 评论(0) 推荐(0) 编辑
摘要: 1 // File Name: 3670.cpp 2 // Author: Missa_Chen 3 // Created Time: 2013年07月08日 星期一 21时15分34秒 4 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 #include 17 #include 18 19 using namespace std;20 21 #define LL long... 阅读全文
posted @ 2013-07-08 23:52 Missa 阅读(279) 评论(0) 推荐(0) 编辑