博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 2642 Stars
阅读量:6836 次
发布时间:2019-06-26

本文共 2181 字,大约阅读时间需要 7 分钟。

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

二维树状数组

代码:

#include 
#include
#include
using namespace std;int a[1005][1005],c[1005][1005];int lowbit(int x){ return x&(-x);}int Sum(int i,int j){ int sum=0,k,p; for(k=i;k>0;k=k-lowbit(k)) for(p=j;p>0;p=p-lowbit(p)) sum+=c[k][p]; return sum;}void change(int i,int j,int x){ int k,p; for(k=i;k<=1004;k=k+lowbit(k)) for(p=j;p<=1004;p=p+lowbit(p)) c[k][p]+=x;}int main(){ int i,j,k,n,m,x,y; char ch; while(cin>>n) { m=n; memset(a,0,sizeof(a)); memset(c,0,sizeof(c)); while(n--) { cin>>ch; if(ch=='B'||ch=='D') { cin>>x>>y; x++;y++; if(ch=='B'&&a[x][y]==0) { change(x,y,1); a[x][y]=1; } if(ch=='D'&&a[x][y]==1) { change(x,y,-1); a[x][y]=0; } } else { int x1,x2,y1,y2; cin>>x1>>x2>>y1>>y2; if(x1>x2) swap(x1,x2); if(y1>y2) swap(y1,y2); cout<
<

转载于:https://www.cnblogs.com/wangyumin/p/5323486.html

你可能感兴趣的文章
englis translate,word
查看>>
ConText
查看>>
java异常捕获
查看>>
Android Service的绑定 基础概念篇
查看>>
MVC项目开发中那些用到的知识点(登录权限认证)
查看>>
错误总结
查看>>
Delphi7 (第一天:类的编写)续
查看>>
单片机基础
查看>>
ZOJ 1027 Human Gene Functions(动态规划LCS)
查看>>
变量、中文-「译」javascript 的 12 个怪癖(quirks)-by小雨
查看>>
合作开发用到的几个 设计模式
查看>>
[iOS] 在UIToolBar中增加UILabel等控件(xib/storyboard图形界面方式)
查看>>
宋体节点hdoj 1520 Anniversary party(树形dp)
查看>>
优化网站设计(七):避免在CSS中使用表达式
查看>>
让你的网站拥有微博(weibo.com)关注图标
查看>>
hadoop基本命令
查看>>
若不能连接到sql server的localhost
查看>>
JavaScript无提示关闭窗口(兼容IE/Firefox/Chrome)
查看>>
Winform窗口里的嵌入WPF的UserControl,关闭Winform父窗体的方法
查看>>
JavaScript – 6.JS面向对象基础(*) + 7.Array对象 + 8.JS中的Dictionary + 9.数组、for及其他...
查看>>