POJ 2029 二维树状数组(400题纪念)
来源:互联网 发布:工艺流程设计软件破解 编辑:程序博客网 时间:2024/06/07 09:17
一道二维树状数组的基础题。
还有好多做法。
数据量小都可以A。
贴这题主要是纪念一下POJ 400AC达成~
继续努力!~~~
#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <iostream>#include <algorithm>#define Max 2505#define FI first#define SE second#define ll long long#define PI acos(-1.0)#define inf 0x3fffffff#define LL(x) ( x << 1 )#define bug puts("here")#define PII pair<int,int>#define RR(x) ( x << 1 | 1 )#define mp(a,b) make_pair(a,b)#define mem(a,b) memset(a,b,sizeof(a))#define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )using namespace std;#define N 200001int n ;int s , e ;int c[555][555] ;int lowbit(int x){return x & (-x) ;}void update(int x , int y ){ for (int i = x ; i <= s ; i += lowbit(i) ) for (int j = y ; j <= e ; j += lowbit(j) ) c[i][j] ++ ;}int query(int x ,int y){ int ans = 0 ; for (int i = x ; i >= 1 ; i -= lowbit(i)) for (int j = y ; j >= 1 ; j -= lowbit(j)) ans += c[i][j] ; return ans ;}int query(int x1 ,int y1 ,int x2 ,int y2){ return query(x2 , y2) + query(x1 - 1 , y1 - 1 ) - query(x1 - 1 , y2) - query(x2 , y1 - 1) ;}void AC2029(){ while(cin >> n , n ){ cin >> e >> s ; mem(c ,0) ; for (int i = 0 ; i < n ; i ++ ){ int x , y ; scanf("%d%d",&x,&y) ; update(y , x) ; } int w , h ; cin >> w >> h ; int ans = 0 ; for (int i = 1 ; i <= s ; i ++ ){ for (int j = 1 ; j <= e ; j ++ ){ int x1 = i ; int y1 = j ; int x2 = x1 + h - 1 ; int y2 = y1 + w - 1 ; if(x2 <= s && y2 <= e) ans = max(ans , query(x1 , y1 , x2 , y2)) ; } } cout << ans << endl; }}int main() { AC2029() ; return 0 ;}
- POJ 2029 二维树状数组(400题纪念)
- POj 2029 (二维树状数组)
- poj 2029(二维树状数组)
- POJ 2029 Get Many Persimmon Trees (二维树状数组)
- POJ 2029 Get Many Persimmon Trees(二维树状数组)
- (POJ 2029)Get Many Persimmon Trees <二维树状数组>
- poj 2029 二维树状数组入门
- POJ 2155 Matrix (二维树状数组+经典题)
- POJ-1195 Mobile phones(二维树状数组裸题)
- poj 1195 (二维树状数组入门,模板题)
- poj 2155 Matrix(二维树状数组)
- poj 2155(二维树状数组)
- poj 2155 (二维树状数组)
- poj 1656(二维树状数组解法)
- POJ 2155 Matrix (二维树状数组)
- POJ 2155 Matrix(二维树状数组)
- 【树状数组(二维)】poj 2155 Matrix
- POJ 2155 Matrix (二维树状数组)
- PropertyDescriptor,BeanUtils,PropertyUtils对javabean的操作
- 大幅度释放
- 学习 pexpect.spawn
- 《剑指Offer》读书笔记---面试题7:用两个队列实现栈
- Exercise 4.2 E2(a) 4.3 E2
- POJ 2029 二维树状数组(400题纪念)
- iOS中定时器NSTimer使用
- thread local storage
- TCP/IP笔记 二.网络层(3)——广播,多播,IGMP
- Delphi异常处理try except语句和try finally语句用法以及区别
- iOS - 操作文件目录的方法
- 问题12:单循环链表解决约瑟夫环问题
- 基本的模板元编程
- Android4.2.2 ViVo Xplay510W 2.16.3/最新官方固件/完美root/完美支持OTA/状态栏流量显示/稳定省电ROM