poj 2029 Get Many Persimmon Trees
来源:互联网 发布:mac版网游加速器 编辑:程序博客网 时间:2024/05/20 07:18
本题可以二维树状数组的思想来解决,暴力好像也可以,数据比较小。用二维树状数组,就是枚举指定长宽的矩阵内*号的个数,并求出数目最大的。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 110;int c[MAXN][MAXN];int lowbit(int x){ return x & (-x);}void Modefy(int x, int y, int data){ for(int i = x; i < MAXN; i += lowbit(i)) for(int j = y; j < MAXN; j += lowbit(j)) c[i][j] += data;}int GetSum(int x, int y){ int sum = 0; for(int i = x; i >0; i -= lowbit(i)) for(int j = y; j > 0; j -= lowbit(j)) sum += c[i][j]; return sum;}int Querry(int x1, int y1, int x2, int y2){ return GetSum(x2, y2) - GetSum(x1-1,y2) - GetSum(x2, y1-1) + GetSum(x1-1,y1-1);}int main(){ int n; int x, y; int w, h; int S, T; while(scanf("%d", &n) != EOF && n) { memset(c, 0, sizeof(c)); scanf("%d %d", &w, &h); for(int i = 1; i <= n; ++i) { scanf("%d %d", &x, &y); Modefy(x, y, 1); } scanf("%d %d", &S, &T); int ans = 0; for(int i = S; i <= w; ++i) for(int j = T; j <= h; ++j) { int sum = Querry(i-S+1, j-T+1, i, j); if(sum > ans) ans = sum; } printf("%d\n", ans); } return 0;}
- POJ 2029 Get Many Persimmon Trees
- Poj 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees [dp]
- POJ 2029 Get Many Persimmon Trees (标记)
- POJ 2029 Get Many Persimmon Trees
- poj-2029-Get Many Persimmon Trees-预处理
- POJ 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- POJ 2029--Get Many Persimmon Trees +DP
- poj 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- poj- 2029 -Get Many Persimmon Trees (DP)
- C++笔试题
- hdu 4790 Just Random
- 【拓展kmp】
- SnagIt - 专业的截图工具
- AngularJS快速开始
- poj 2029 Get Many Persimmon Trees
- Debian下实验Linux Container命令简记
- Linux最大线程数限制及当前线程数查询
- 基于xmpp openfire smack开发之Android客户端开发[3]
- 基于xmpp openfire smack开发之Android消息推送技术原理分析和实践[4]
- RapidXml使用方法
- CodeForces 300C Beautiful Numbers 组合数取余
- struts2之单个文件上传
- Showing a Splash Screen whilst initializing a WPF Prism application