Stars

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others)
Total Submission(s): 975    Accepted Submission(s): 420

Problem Description
Yifenfei is a romantic guy and he likes to count the stars in the sky.
To make the problem easier,we considerate the sky is a two-dimension plane.Sometimes the star will be bright and sometimes the star will be dim.At first,there is no bright star in the sky,then some information will be given as "B x y" where 'B' represent bright and x represent the X coordinate and y represent the Y coordinate means the star at (x,y) is bright,And the 'D' in "D x y" mean the star at(x,y) is dim.When get a query as "Q X1 X2 Y1 Y2",you should tell Yifenfei how many bright stars there are in the region correspond X1,X2,Y1,Y2.

There is only one case.

 
Input
The first line contain a M(M <= 100000), then M line followed.
each line start with a operational character.
if the character is B or D,then two integer X,Y (0 <=X,Y<= 1000)followed.
if the character is Q then four integer X1,X2,Y1,Y2(0 <=X1,X2,Y1,Y2<= 1000) followed.
 
Output
For each query,output the number of bright stars in one line.
 
Sample Input
5 B 581 145 B 581 145 Q 0 600 0 200 D 581 145 Q 0 600 0 200
 
Sample Output
1 0
 
Author
teddy
 
Source
 
树状数组,用到二维,当时总的的来说,还算简单。。。
题目要求求矩形里星星中的个数//
给定某两个坐标对角坐标,球该矩形的星星个数..
对于x1,x2,y1,y2.。我们不知道其大小,所以需要进行比较
得到大小之后,我们就可以求该巨型的了,像下面的图一样..
 
由此贴出代码吧:
 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 1005
#define lowbit(x) ((x)&(-x))
int aa[maxn][maxn];
bool bb[maxn][maxn]; void ope(int x,int y,int val)
{
int j;
if(val==)
{
if(bb[x][y]) return ;
bb[x][y]=true;
}
else
{
if(bb[x][y]==false)
return ;
bb[x][y]=false;
}
while(x<maxn){
j=y;
while(j<maxn){
aa[x][j]+=val;
j+=lowbit(j);
}
x+=lowbit(x);
}
}
int sum(int x,int y)
{
int ans= ,j;
while(x>){
j=y;
while(j>){
ans+=aa[x][j];
j-=lowbit(j);
}
x-=lowbit(x);
}
return ans;
}
struct node
{
int x;
int y;
};
int main()
{
int test,res;
char str[];
node a,b;
memset(aa,,sizeof(aa));
memset(bb,,sizeof(bb));
scanf("%d",&test);
while(test--)
{
scanf("%s",str);
if(str[]=='Q')
{
scanf("%d%d%d%d",&a.x,&b.x,&a.y,&b.y);
if(a.x>b.x){
a.x^=b.x;
b.x^=a.x;
a.x^=b.x;
}
if(a.y>b.y){
a.y^=b.y;
b.y^=a.y;
a.y^=b.y;
}
b.x++;
b.y++;
res=sum(b.x,b.y)-sum(a.x,b.y)+sum(a.x,a.y)-sum(b.x,a.y);
printf("%d\n",res);
}
else
{
scanf("%d%d",&a.x,&a.y);
a.x++; //ÓÒÒÆÒ»Î»
a.y++;
if(str[]=='B')
ope(a.x,a.y,);
else
ope(a.x,a.y,-);
}
}
return ;
}
 

HDUOJ---2642Stars(二维树状数组)的更多相关文章

  1. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

  2. HDU1559 最大子矩阵 (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)  ...

  3. POJMatrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22058   Accepted: 8219 Descripti ...

  4. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  5. Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*

    D. Iahub and Xors   Iahub does not like background stories, so he'll tell you exactly what this prob ...

  6. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  7. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  8. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

  9. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

  10. MooFest_二维树状数组

    Description Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a s ...

随机推荐

  1. Cocos2d-x

    http://blog.csdn.net/ccf19881030/article/details/9204801 Cocos2d-x相关的博客以及官网信息 1.CSDN博主无幻的博客:http://b ...

  2. inline

    inline 大学在教科书上学习过inline函数,定义为inline函数之后,会省去函数调用的开销,直接嵌套汇编代码,取代函数调用,提高效率.工作后项目中也很少用到inline来定义函数,近几天在研 ...

  3. 为apache安装mod_wsgi的时候出现-fpic的问题

    1.为了在apache里跑python项目,需要安装模块mod_wsgi 2.但是由于yum只支持python2.6,所以通过yum install mod_wsgi方式安装的mod_wsgi是pyt ...

  4. 混沌数学之Henon吸引子

    Henon吸引子是混沌与分形的著名例子. 相关软件:混沌数学及其软件模拟相关代码: // http://wenku.baidu.com/view/d51372a60029bd64783e2cc0.ht ...

  5. max-sum-of-sub-matrix-no-larger-than-k

    根据上一篇文章提到的参考文档: https://leetcode.com/discuss/109749/accepted-c-codes-with-explanation-and-references ...

  6. Informatica 常用组件Filter之二 过滤条件

    过滤条件可以使用转换语言输入.过滤条件是返回 TRUE 或 FALSE 的表达式.例如,如果您要过滤出员工薪水低于 $30,000 的行,可输入以下条件: SALARY > 30000 可以使用 ...

  7. 点云数据(point cloud) 【转】

    转自caimagic的专栏 一:什么是点云数据 点云数据是指在一个三维坐标系统中的一组向量的集合.这些向量通常以X,Y,Z三维坐标的形式表示,而且一般主要用来代表一个物体的外表面形状.不经如此,除(X ...

  8. IOS系统之蓝牙外接设备

    Ios系统对于蓝牙外接设备在iphone4以前都是蓝牙2.0的时候,需要通过苹果的审核,据统计通过率仅有2%左右,现在蓝牙2.0基本上处于淘汰状态,所以在这里就不考虑了. 现在iphone4s以后的设 ...

  9. Android -- 打开本地图片且显示路径

    背景                                                                                          代码       ...

  10. 在CentOS/RHEL上设置SSH免密码登录

    本文会告诉你怎样在 CentOS/RHEL 上设置 SSH 免密码登录.自动登录配置好以后,你可以通过它使用 SSH (Secure Shell)和安全复制 (SCP)来移动文件. SSH 是开源的, ...