标签:des style blog http color strong
http://poj.org/problem?id=2155
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 17721 | Accepted: 6653 |
Description
Input
Output
Sample Input
1 2 10 C 2 1 2 2 Q 2 2 C 2 1 2 1 Q 1 1 C 1 1 2 1 C 1 2 1 2 C 1 1 2 2 Q 1 1 C 1 1 2 1 Q 2 1
Sample Output
1 0 0
1
//////////////////////////////////////////////
二维树状数组题,挺难理解的,楼教主的经典题啊,还是要慢慢才能理解
参考下这个链接:http://blog.csdn.net/zxy_snow/article/details/6264135
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #define Maxx 1005 int n,m; int c[Maxx][Maxx]; int Lowbit(int x) { return x&(-x); } void Update(int x,int y,int i) { int y1; while(x<=n) { y1=y; while(y1<=n) { c[x][y1]+=i; y1+=Lowbit(y1); } x+=Lowbit(x); } } int GetSum(int x,int y) { int s=0; while(x>0) { int y1=y; while(y1>0) { s+=c[x][y1]; y1-=Lowbit(y1); } x-=Lowbit(x); } return s; } int main() { int i,j,t; char cas; int x1,y1,x,y,a,b; scanf("%d",&t); while(t--) { memset(c,0,sizeof(c)); scanf("%d%d%*c",&n,&m); while(m--) { scanf("%c",&cas); if(cas == ‘C‘) { scanf("%d%d%d%d%*c",&x,&y,&x1,&y1); x++;y++;x1++;y1++; Update(x1,y1,1); Update(x-1,y1,1); Update(x1,y-1,1); Update(x-1,y-1,1); } else { scanf("%d%d%*c",&a,&b); printf("%d\n",GetSum(a,b)%2); } } printf("\n"); } return 0; }
poj 2155 二维树状数组,布布扣,bubuko.com
标签:des style blog http color strong
原文地址:http://www.cnblogs.com/ccccnzb/p/3839741.html