2012年11月26日

摘要: 题意很简单,就是求n个矩形的周长并。方法跟求面积并差不多,只是在扫描矩形上下边时需要统计竖直边的个数,先排个序,每次更新求出变化的和。View Code 1 #include <stdio.h> 2 #include <math.h> 3 #define lson l,m,rt<<1 4 #define rson m+1,r,rt<<1|1 5 #define maxn 20005 6 struct node 7 { 8 int len,lnum,rnum,cnt,segnum; 9 }setree[maxn<<2]; 10 stru 阅读全文
posted @ 2012-11-26 22:04 kim888168 阅读(131) 评论(0) 推荐(0) 编辑
 
摘要: 题意:给出n个矩形的左下坐标和右上坐标,求出总面积。在写pushup函数时,没有考虑l==r的情况,wa了很久。看了其他大牛的解题报告才想起来的。╭(╯^╰)╮View Code 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 205 7 struct node 8 { 9 double len; 10 int cnt; 11 阅读全文
posted @ 2012-11-26 11:15 kim888168 阅读(127) 评论(0) 推荐(0) 编辑

2012年11月24日

摘要: 这是一道模拟内存分配操作的题目,几乎包含了线段树的各种基本操作,跟poj3667 hotel差不多的功能,只是多了一个统计区间个数的操作。由于这题是断断续续打上去的,花的时间也比较长。可能有些代码写的不太好。View Code 1 #include <stdio.h> 2 #define lson l,m,rt<<1 3 #define rson m+1,r,rt<<1|1 4 #define maxn 50005 5 struct node 6 { 7 int llen,rlen,maxlen,lnum,rnum,num,cnt; 8 }setree[ma 阅读全文
posted @ 2012-11-24 23:04 kim888168 阅读(183) 评论(0) 推荐(0) 编辑

2012年11月23日

摘要: 题目大意:有排成一行的村庄,开始时彼此相连。现在又三种操作:(1):D x 破坏x村庄(2):R 修复上一次被破坏的村庄(3):Q x是求包含村庄x的最长相连村庄数。比较坑爹的是poj和hdu的R操作有所不同。比如执行了下列操作:D 2D 4D 2R在poj修复的是村庄4,而hdu修复的是村庄2.这是需要注意的。下面是在poj过的代码。View Code 1 #include <stdio.h> 2 #include <string.h> 3 #define lson l,m,rt<<1 4 #define rson m+1,r,rt<<1|1 阅读全文
posted @ 2012-11-23 15:30 kim888168 阅读(123) 评论(0) 推荐(0) 编辑

2012年11月19日

摘要: 题目大意:对于一个给定的字符串(有‘b’和‘w’组成),求其中“wbw”的数目。这题刚开始做时没什么思路,或许跟我本来就讨厌字符串这类题有关吧。好,废话少说,讲讲思路吧。这题其实是考线段树的,单点更新,区间合并。合并时要注意一下边界,详细的还是自己看看代码吧。View Code 1 #include <stdio.h> 2 #define lson l,m,rt<<1 3 #define rson m+1,r,rt<<1|1 4 #define maxn 50000 5 struct node 6 { 7 int cnt; 8 }setree[maxn< 阅读全文
posted @ 2012-11-19 11:05 kim888168 阅读(148) 评论(0) 推荐(0) 编辑

2012年11月16日

摘要: 题意:小Q被邪恶的大魔王困在了迷宫里,love8909决定去解救她。 迷宫里面有一些陷阱,一旦走到陷阱里,就会被困身亡:(,迷宫 里还有一些古老的传送阵,一旦走到传送阵上,会强制被传送到 传送阵的另一头。 现在请你帮助love8909算一算,他至少需要走多少步才能解 救到小Q?思路:bfsView Code 1 #include <stdio.h> 2 #include <string.h> 3 struct node 4 { 5 int x1,y1,x2,y2; 6 }belt[26]; 7 struct 8 { 9 int x0,y0,count; 1... 阅读全文
posted @ 2012-11-16 10:39 kim888168 阅读(326) 评论(0) 推荐(0) 编辑

2012年11月10日

摘要: 题目大意:初始时S为空集,经过一系列操作(区间的交,并,补,差等),求最后一条命令执行之后的集合S。思路:集合T表示为(a,b).(1)'U':将(a,b)置1。(2)'I':将(0,a-1)和(b+1,maxn)之置0。(3)'D':将(a,b)置0;(4)'C':将(0,a-1)和(b+1,maxn)置0,(a,b)进行异或操作。(5)‘S’:将(a,b)进行抑或操作。由于进行‘I’和‘C’操作时,没有判断边界,贡献了无数个re。-_-#做了这题,发现自己太过粗心,必须客服。。。。。View Code 1 #include & 阅读全文
posted @ 2012-11-10 16:37 kim888168 阅读(152) 评论(0) 推荐(0) 编辑

2012年11月8日

摘要: 题目大意:一块高为h,宽为m的墙,在墙上涂上不同颜色的矩形,求经过一系列操作后每种颜色相应的面积和颜色种数。需要注意的是输出时要判断颜色种数,如果是1或0要用is,否则用are(这里害我wa了好几次)。-_-!思路:离散化。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 int a[205][205]; 6 struct 7 { 8 int x,y; 9 }bottomleft[105],topright[10 阅读全文
posted @ 2012-11-08 23:05 kim888168 阅读(157) 评论(0) 推荐(0) 编辑
 
摘要: 题目大意:一个农园有n个花朵,给出每朵花的开花时间(用区间表示),求在特定时间点的开花的花朵数量。思路:离散化,线段树。在建树时有些点表示单个时间点,有些要表示时间区间。然后单点查询即可。View Code 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 100010 8 s 阅读全文
posted @ 2012-11-08 09:29 kim888168 阅读(139) 评论(0) 推荐(0) 编辑

2012年11月7日

摘要: 题目大意:就是求一个数n的最大素数因子。思路:类似于筛素数,每次记录当前最大的素数因子,并同时记录该素数的序号。View Code #include <stdio.h>#include <string.h>int prime[1000000];int pos[1000000];int main(){ int i,j,k=1,n; prime[1]=1; pos[1]=0; memset(prime,0,sizeof(prime)); for(i=2;i<1000000;i++) if(prime[i]==0){ prime[i]=i; ... 阅读全文
posted @ 2012-11-07 21:40 kim888168 阅读(130) 评论(0) 推荐(0) 编辑