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 ;
}
 

最新文章

  1. Oracle闪回技术详解
  2. dojo 三 类和继承 dojo/_base/declare
  3. OpenGL超级宝典第5版&amp;&amp;基础渲染
  4. Android开发UI之在子线程中更新UI
  5. 解决eclipse无法解析shared_ptr
  6. 用MFC实现WebGUI--(CDHtmlDialog)
  7. 设计管理员表;webservice用于网络安全的高端内提供服务的
  8. NumPy基础:数组和矢量计算
  9. javascript语句语义大全(1)
  10. 邮件报警shell脚本
  11. 【转】MySQL乐观锁在分布式场景下的实践
  12. 严格次小生成树(Bzoj1977:[Beijing2010组队]次小生成树)
  13. 对于spring中事务@Transactional注解的理解
  14. VS2017编译SNMP++步骤记录
  15. kindeditor用法简单介绍(转)
  16. django模型系统一
  17. 《Linux内核分析》第八周笔记 进程的切换和系统的一般执行过程
  18. Hbase 命令小结
  19. 第15课-数据库开发及ado.net-数据库介绍,主键,外键,启动数据库,数据库身份验证方式,建表,分离数据库
  20. Java后端,应该日常翻看的中文技术网站

热门文章

  1. Visual Studio 2013键盘码农常用快捷键
  2. 我所遭遇过的中间件--3D MAX SDK
  3. 我所遭遇过的中间件--VTK
  4. ING【转载】epoll总结系列
  5. iOS开发--整理常用的第三方资源
  6. Bootstrap学习js插件篇之提示框
  7. C# 特性(Attribute)(二)
  8. SQL Server 视图索引
  9. centos7 JDK1.8
  10. Bootstrap3实现的响应式幻灯滑动效果个人作品集/博客网站模板