See you~(hdu1892)

See you~

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 4768    Accepted Submission(s): 1521

Problem Description

Now
I am leaving hust acm. In the past two and half years, I learned so
many knowledge about Algorithm and Programming, and I met so many good
friends. I want to say sorry to Mr, Yin, I must leave now ~~>.<~~.
I am very sorry, we could not advanced to the World Finals last year.
When
coming into our training room, a lot of books are in my eyes. And every
time the books are moving from one place to another one. Now give you
the position of the books at the early of the day. And the moving
information of the books the day, your work is to tell me how many books
are stayed in some rectangles.
To make the problem easier, we
divide the room into different grids and a book can only stayed in one
grid. The length and the width of the room are less than 1000. I can
move one book from one position to another position, take away one book
from a position or bring in one book and put it on one position.

Input

In
the first line of the input file there is an Integer T(1<=T<=10),
which means the number of test cases in the input file. Then N test
cases are followed.
For each test case, in the first line there is
an Integer Q(1<Q<=100,000), means the queries of the case. Then
followed by Q queries.
There are 4 kind of queries, sum, add, delete and move.
For example:
S
x1 y1 x2 y2 means you should tell me the total books of the rectangle
used (x1,y1)-(x2,y2) as the diagonal, including the two points.
A x1 y1 n1 means I put n1 books on the position (x1,y1)
D x1 y1 n1 means I move away n1 books on the position (x1,y1), if less than n1 books at that position, move away all of them.
M
x1 y1 x2 y2 n1 means you move n1 books from (x1,y1) to (x2,y2), if less
than n1 books at that position, move away all of them.
Make sure that at first, there is one book on every grid and 0<=x1,y1,x2,y2<=1000,1<=n1<=100.

Output

At the beginning of each case, output "Case X:" where X is the index of the test case, then followed by the "S" queries.
For each "S" query, just print out the total number of books in that area.

Sample Input

2
3
S 1 1 1 1
A 1 1 2
S 1 1 1 1
3
S 1 1 1 1
A 1 1 2
S 1 1 1 2

Sample Output

Case 1:
1
3
Case 2:
1
4

Author

Sempr|CrazyBird|hust07p43

思路:二维树状数组;

套个二维的模板就行,注意给的两个点的大小关系;

  1 #include<stdio.h>
  2 #include<algorithm>
  3 #include<iostream>
  4 #include<stdlib.h>
  5 #include<queue>
  6 #include<string.h>
  7 #include<map>
  8 #include<vector>
  9 #include<queue>
 10 using namespace std;
 11 typedef long long LL;
 12 int ma[1005][1005];
 13 int bit[1005][1005];
 14 int cit[1005][1005];
 15 int lowbit(int x);
 16 void add(int x,int y,int c,int v);
 17 int ask(int x,int y);
 18 int main(void)
 19 {
 20         int n;
 21         scanf("%d",&n);
 22         int __ca = 0;
 23         int i,j;
 24         for(i = 1; i <= 1001; i++)
 25         {
 26                 for(j = 1; j <= 1001; j++)
 27                 {
 28                         ma[i][j] = 1;
 29                         add(i,j,1,0);
 30                 }
 31         }
 32         while(n--)
 33         {
 34                 memset(bit,0,sizeof(bit));
 35                 int m;
 36                 for(i = 0; i <= 1001; i++)
 37                 {
 38                         for(j = 0; j <= 1001; j++)
 39                         {
 40                                 bit[i][j] = cit[i][j];
 41                         }
 42                 }
 43                 for(i = 0; i <= 1001; i++)
 44                 {
 45                         for(j = 0; j <= 1001; j++)
 46                         {
 47                                 ma[i][j] = 1;
 48                         }
 49                 }
 50                 char ans[10];
 51                 scanf("%d",&m);
 52                 printf("Case %d:\n",++__ca);
 53                 while(m--)
 54                 {
 55                         scanf("%s",ans);
 56                         int x,y,x1,y1;
 57                         if(ans[0]==‘S‘)
 58                         {
 59                                 scanf("%d %d %d %d",&x,&y,&x1,&y1);
 60                                 if(x > x1)
 61                                         swap(x,x1),swap(y,y1);
 62                                 if(y > y1)
 63                                 {
 64                                         swap(y,y1);
 65                                 }
 66                                 x++;
 67                                 y++;
 68                                 x1++;
 69                                 y1++;
 70                                 int sum = ask(x1,y1);
 71                                 sum -= ask(x-1,y1);
 72                                 sum -= ask(x1,y-1);
 73                                 sum += ask(x-1,y-1);
 74                                 printf("%d\n",sum);
 75                         }
 76                         else if(ans[0] == ‘A‘)
 77                         {
 78                                 int c;
 79                                 scanf("%d %d %d",&x,&y,&c);
 80                                 x++;
 81                                 y++;
 82                                 ma[x][y] += c;
 83                                 add(x,y,c,1);
 84                         }
 85                         else if(ans[0] == ‘M‘)
 86                         {
 87                                 int c;
 88                                 scanf("%d %d %d %d %d",&x,&y,&x1,&y1,&c);
 89                                 x++;
 90                                 y++;
 91                                 x1++;
 92                                 y1++;
 93                                 if(ma[x][y] < c)
 94                                         c = ma[x][y];
 95                                 ma[x][y] -= c;
 96                                 ma[x1][y1]+=c;
 97                                 add(x,y,-c,1);
 98                                 add(x1,y1,c,1);
 99                         }
100                         else
101                         {
102                                 int c;
103                                 scanf("%d %d %d",&x,&y,&c);
104                                 x++;
105                                 y++;
106                                 if(ma[x][y] < c)
107                                         c = ma[x][y];
108                                 ma[x][y] -= c;
109                                 add(x,y,-c,1);
110                         }
111                 }
112         }
113         return 0;
114 }
115 int lowbit(int x)
116 {
117         return x&(-x);
118 }
119 void add(int x,int y,int c,int v)
120 {
121         int i,j;
122         for(i = x; i <= 1001; i += lowbit(i))
123         {
124                 for(j = y; j <= 1001; j += lowbit(j))
125                 {
126                         if(v)
127                                 bit[i][j] += c;
128                         else cit[i][j]+=c;
129                 }
130         }
131 }
132 int ask(int x,int y)
133 {
134         int i,j;
135         int sum = 0;
136         for(i = x; i > 0; i -= lowbit(i))
137         {
138                 for(j = y; j > 0; j -= lowbit(j))
139                 {
140                         sum += bit[i][j];
141                 }
142         }
143         return sum;
144 }
时间: 2024-12-29 05:21:26

See you~(hdu1892)的相关文章

使用 IDEA 创建 Maven Web 项目 (异常)- Disconnected from the target VM, address: &#39;127.0.0.1:59770&#39;, transport: &#39;socket&#39;

运行环境: JDK 版本:1.8 Maven 版本:apache-maven-3.3.3 IDEA 版本:14 maven-jetty-plugin 配置: <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <configuration> <webAppSourceDirectory>${pro

在深圳有娃的家长必须要懂的社保少儿医保,不然亏大了!(收藏)

在深圳有娃的家长必须要懂的社保少儿医保,不然亏大了!(收藏) 转载2016-07-26 17:21:47 标签:深圳少儿医保社保医疗保险住院 在深圳工作或生活的家长们可能还有人不清楚,其实小孩子最大的基础保障福利就是少儿医保.如果以前没重视关注的,现在您看到这篇文章还来得及!少儿医保每年政府财政补贴384元,自己只需交200元左右,就可以享受门诊报销1000元,住院报销比例90%,最高报销额度达148万,大病门诊最高报销比例90%!如何享受?有哪些待遇?接下来就详细来做一个介绍: 少儿医保投保需

彻底解决_OBJC_CLASS_$_某文件名&quot;, referenced from:问题(转)

最近在使用静态库时,总是出现这个问题.下面总结一下我得解决方法: 1. .m文件没有导入   在Build Phases里的Compile Sources 中添加报错的文件 2. .framework文件没有导入静态库编译时往往需要一些库的支持,查看你是否有没有导入的库文件同样是在Build Phases里的Link Binary With Libraries中添加 3. 重复编译,可能你之前复制过两个地方,在这里添加过两次,删除时系统没有默认删除编译引用地址在Build Settings里搜索

爱奇艺、优酷、腾讯视频竞品分析报告2016(一)

1 背景 1.1 行业背景 1.1.1 移动端网民规模过半,使用时长份额超PC端 2016年1月22日,中国互联网络信息中心 (CNNIC)发布第37次<中国互联网络发展状况统计报告>,报告显示,网民的上网设备正在向手机端集中,手机成为拉动网民规模增长的主要因素.截至2015年12月,我国手机网民规模达6.20亿,有90.1%的网民通过手机上网. 图 1  2013Q1~2015Q3在线视频移动端和PC端有效使用时长份额对比 根据艾瑞网民行为监测系统iUserTracker及mUserTrac

Android 导航条效果实现(六) TabLayout+ViewPager+Fragment

TabLayout 一.继承结构 public class TabLayout extends HorizontalScrollView java.lang.Object ? android.view.View ? android.view.ViewGroup ? android.widget.FrameLayout ? android.widget.HorizontalScrollView ? android.support.design.widget.TabLayout 二.TabLayou

微信小程序——豆瓣电影——(2):小程序运行部署

Demo 预览 演示视频(流量预警 2.64MB) GitHub Repo 地址 仓库地址:https://github.com/zce/weapp-demo 使用步骤 将仓库克隆到本地: bash $ git clone https://github.com/zce/weapp-demo.git weapp-douban --depth 1 $ cd weapp-douban 打开微信Web开放者工具(注意:必须是0.9.092300版本) 必须是0.9.092300版本,之前的版本不能保证正

初识运维3--在虚拟机中安装Linux发行版系统(CentOS)的方法

在讲Linux系统发行版本的安装过程之前,先大略说明一下虚拟化. 虚拟化:将底层硬件资源抽象为用户更容易读懂和使用的逻辑抽象层的技术. 最早由IBM提出,现使用率较高的虚拟化软件平台有三类:VMware workstation.VirtualBOX.HyperV.在这里使用VMware workstation作为例子讲解说明安装过程. 虚拟化网络: 桥接模式:让物理机和虚拟机利用物理网络接口完成通信.虚拟机可以访问互联网. 仅主机模式:让虚拟机和物理机利用被虚拟出来的VMnet1网络接口完成通信

pythonの函数学习笔记(一)

函数是可以实现一些特定功能的小方法或小程序定义函数function的方法:def function_name(arg1,arg2[,...]): statement [return value]注意事项:1.def开头,代表定义函数,def和函数名中间要敲一个空格:2.返回值不是必须的,如果没有renturn语句,则默认返回值None:3.函数名必须以下划线或字母开头,可以包含任意字母.数字或下划线的组合,区分大小写且不能是保留字: py使用名称空间的概念存储对象,这个名称空间就是对象作用的区域

网络攻防第一次作业(201421450010)

姓名:陈书扬 学号:201421450010 指导教师:高见 1.虚拟机安装与调试 安装windows和linux(kali)两个虚拟机,均采用NAT网络模式,查看主机与两个虚拟机器的IP地址,并确保其连通性.同时为两个虚拟机做一个快照 windows虚拟机 Linux虚拟机 本地主机win10 两台主机都ping通 2.Windows基本命令 dir显示目录   cd 进入目录 Arp -a -d -s arp缓存 net share 查看计算机IPC$共享资源 netstat -ano网络链