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
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.
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.
For each "S" query, just print out the total number of books in that area.
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
1
3
Case 2:
1
4
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 }
See you~(hdu1892)的更多相关文章
- Angular2入门系列教程7-HTTP(一)-使用Angular2自带的http进行网络请求
上一篇:Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数 感觉这篇不是很好写,因为涉及到网络请求,如果采用真实的网络请求,这个例子大家拿到手估计还要自己写一个web ...
- Angular2学习笔记(1)
Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...
- ASP.NET Core 之 Identity 入门(一)
前言 在 ASP.NET Core 中,仍然沿用了 ASP.NET里面的 Identity 组件库,负责对用户的身份进行认证,总体来说的话,没有MVC 5 里面那么复杂,因为在MVC 5里面引入了OW ...
- ABP入门系列(1)——学习Abp框架之实操演练
作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...
- Online Judge(OJ)搭建(第一版)
搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...
- 如何一步一步用DDD设计一个电商网站(九)—— 小心陷入值对象持久化的坑
阅读目录 前言 场景1的思考 场景2的思考 避坑方式 实践 结语 一.前言 在上一篇中(如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成),有一行注释的代码: public interfa ...
- 如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成
阅读目录 前言 建模 实现 结语 一.前言 前面几篇已经实现了一个基本的购买+售价计算的过程,这次再让售价丰满一些,增加一个会员价的概念.会员价在现在的主流电商中,是一个不大常见的模式,其带来的问题是 ...
- 【.net 深呼吸】细说CodeDom(5):类型成员
前文中,老周已经厚着脸皮介绍了类型的声明,类型里面包含的自然就是类型成员了,故,顺着这个思路,今天咱们就了解一下如何向类型添加成员. 咱们都知道,常见的类型成员,比如字段.属性.方法.事件.表示代码成 ...
- 【.net 深呼吸】细说CodeDom(4):类型定义
上一篇文章中说了命名空间,你猜猜接下来该说啥.是了,命名空间下面就是类型,知道了如何生成命名空间的定义代码,之后就该学会如何声明类型了. CLR的类型通常有这么几种:类.接口.结构.枚举.委托.是这么 ...
随机推荐
- gcc 引用math 库 编译的问题 解决方法
1.gcc app.c -lm 其中lm表示的是连接 m forlibm.so / libm.a表示你想要的库 abc for libabc.so / libabc.a 其中.a表示的是静态链接库 . ...
- 联盛德 HLK-W806 (六): I2C驱动SSD1306 128x64 OLED液晶屏
目录 联盛德 HLK-W806 (一): Ubuntu20.04下的开发环境配置, 编译和烧录说明 联盛德 HLK-W806 (二): Win10下的开发环境配置, 编译和烧录说明 联盛德 HLK-W ...
- HDFS03 HDFS的API操作
HDFS的API操作 目录 HDFS的API操作 客户端环境准备 1.下载windows支持的hadoop 2.配置环境变量 3 在IDEA中创建一个Maven工程 HDFS的API实例 用客户端远程 ...
- 大数据学习day11------hbase_day01----1. zk的监控机制,2动态感知服务上下线案例 3.HDFS-HA的高可用基本的工作原理 4. HDFS-HA的配置详解 5. HBASE(简介,安装,shell客户端,java客户端)
1. ZK的监控机制 1.1 监听数据的变化 (1)监听一次 public class ChangeDataWacher { public static void main(String[] arg ...
- 100个Shell脚本——【脚本8】每日生成一个文件
[脚本8]每日生成一个文件 要求:请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为)2017-07-05.log, 并且把磁盘的使用情况写到到这个文件中,(不用考虑c ...
- c3p0的使用步骤
//1.导入c3p0的连个包,和mysql的驱动包//2.配置c3p0.xml的配置文件 <c3p0-config> <!-- 使用默认的配置读取连接池对象 --> <d ...
- Mysql配置文件 客户端
[client] #默认链接的端口 port=3306 #默认链接的socket的位置 socket=/var/lib/mysql.sock #默认编码格式 default-character-set ...
- <转>libevent基本使用demo
这篇文章介绍下libevent在socket异步编程中的应用.在一些对性能要求较高的网络应用程序中,为了防止程序阻塞在socket I/O操作上造成程序性能的下降,需要使用异步编程,即程序准备好读写的 ...
- Wireshark(五):TCP窗口与拥塞处理
原文出处: EMC中文支持论坛 TCP通过滑动窗口机制检测丢包,并在丢包发生时调整数据传输速率.滑动窗口机制利用数据接收端的接收窗口来控制数据流. 接收窗口值由数据接收端指定,以字节数形式存储于TCP ...
- 我在这里的处女篇(Word技巧集团)
传说这里的文章可以在Word上打好了发布,Word嘛,有[听写]功能,不用打字了: 写好的文章还可以[大声朗读],边听边看最容易找"通假字"了. 冲这,我的新阵地就定这里了,哈哈~