摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042用数组来存储结果~~~代码: 1 #include <stdio.h> 2 #include <string.h> 3 #define N 50002 4 5 int a[N]; 6 7 void calculator(int n) 8 { 9 int i, j, c = 0;10 a[1] = 1;11 for(i = 1; i <= n; i++)12 {13 for(j = 1; j <= N; j++)14 {15 ... 阅读全文
posted @ 2012-09-03 19:18 山路水桥 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754区间求和问题~~~代码:#include <stdio.h>#define N 200002#define M 5002#define L(x) ((x)<<1)#define R(x) ((x)<<1|1)typedef struct{ int lson, rson; int val;} seg_tree;seg_tree s[N<<2];int num[N];int build(int left, int right, int idx){ s 阅读全文
posted @ 2012-09-03 19:16 山路水桥 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166区间求和问题~~~代码如下: 1 #include <stdio.h> 2 #include <string.h> 3 #define N 50002 4 #define L(x) ((x)<<1) 5 #define R(x) ((x)<<1|1) 6 7 typedef struct 8 { 9 int lson, rson; 10 int val; 11 } seg_tree; 12 13 seg_tree s[N<<2]; 1 阅读全文
posted @ 2012-09-03 19:15 山路水桥 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394区间求和问题,但是用暴力方法也能通过,线段树50MS可以解决,暴力要250多MS,这就是算法的魅力所在~~~线段树代码: 1 #include <stdio.h> 2 #define L(x) ((x) << 1) 3 #define R(x) ((x) << 1 | 1) 4 #define N 5001 5 6 typedef struct 7 { 8 int lson, rson; 9 int val;10 } seg_tree;11 seg_tree 阅读全文
posted @ 2012-09-03 19:13 山路水桥 阅读(650) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698属于区间染色与区间求和问题,用线段树解决~~~代码如下: 1 #include <stdio.h> 2 #define N 300002 3 #define LL(x) ((x)<<1) 4 #define RR(x) ((x)<<1|1) 5 6 typedef struct 7 { 8 int lson, rson; 9 int val;10 } seg_tree;11 12 seg_tree s[N];13 14 void build(int left 阅读全文
posted @ 2012-09-03 19:09 山路水桥 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 线段树//zoj 1610 线段覆盖//poj 2777 线段覆盖//poj 2528 需要离散化,建树不同,需要处理不同->注意这组数据 3 1 10 1 3 6 10 the ans is 3.//hdu 1754 求区间最大值//hdu 1166 求区间和//hdu 1698 成段更新//poj 3468 成段更新//ural 1019 覆盖加统计最长同一个颜色//zoj 2301 和上一题差不多,但是这个染色染的是点,注意染色为空的状况//poj 3264 水题,寻找区间最大最小值//poj 1151 线段树+离散化求矩形面积并//poj 1177 矩形周长并//poj 3277 阅读全文
posted @ 2012-09-03 09:38 山路水桥 阅读(1714) 评论(0) 推荐(1) 编辑
摘要: 原文转自:http://www.cppblog.com/MatoNo1/archive/2011/04/17/144390.aspxKMP:给出两个字符串A(称为模板串)和B(称为子串),长度分别为lenA和lenB,要求在线性时间内,对于每个A[i](0k,所以又有A[i..p]==B[i-k..... 阅读全文
posted @ 2012-09-03 01:02 山路水桥 阅读(9121) 评论(2) 推荐(4) 编辑