POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】
题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树
二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过500,直接暴力
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include <cmath>
- #include<stack>
- #include<vector>
- #include<map>
- #include<set>
- #include<queue>
- #include<algorithm>
- using namespace std;
- typedef long long LL;
- const int INF = (<<)-;
- const int mod=;
- const int maxn=;
- int c[maxn][maxn];
- int lowbit(int x){ return x & (-x);}
- int sum(int x,int y){
- int ret=;
- int y1;
- while(x > ){
- y1=y;
- while(y1 > ){
- ret += c[x][y1];y1-=lowbit(y1);
- }
- x-=lowbit(x);
- }
- return ret;
- }
- void add(int x,int y,int d){
- int y1;
- while(x < maxn){
- y1=y;
- while(y1 < maxn){
- c[x][y1] += d;y1+=lowbit(y1);
- }
- x+=lowbit(x);
- }
- }
- int main(){
- int n;
- while(scanf("%d",&n)!=EOF && n){
- memset(c,,sizeof(c));
- int w,h;
- scanf("%d %d",&w,&h);
- while(n--){
- int u,v;
- scanf("%d %d",&u,&v);
- add(v,u,);
- }
- int x,y;
- scanf("%d %d",&x,&y);swap(x,y);
- int ans=-;
- int tmp=;
- for(int i=;i <=h;i++){
- for(int j=;j<=w;j++){
- tmp = sum(i+x-,j+y-)-sum(i-,j+y-)-sum(i+x-,j-)+sum(i-,j-);
- ans = max(ans,tmp);
- }
- }
- printf("%d\n",ans);
- }
- return ;
- }
POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】的更多相关文章
- POJ2029:Get Many Persimmon Trees(二维树状数组)
Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...
- [poj2155]Matrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25004 Accepted: 9261 Descripti ...
- POJ 2029 Get Many Persimmon Trees (二维树状数组)
Get Many Persimmon Trees Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I ...
- POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)
题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio ...
- POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】
<题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...
- POJ 2029 (二维树状数组)题解
思路: 大力出奇迹,先用二维树状数组存,然后暴力枚举 算某个矩形区域的值的示意图如下,代码在下面慢慢找... 代码: #include<cstdio> #include<map> ...
- Get Many Persimmon Trees_枚举&&二维树状数组
Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- POJ 2155 Matrix【二维树状数组+YY(区间计数)】
题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- POJ 2155 Matrix(二维树状数组,绝对具体)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20599 Accepted: 7673 Descripti ...
随机推荐
- 高并发之后端优化(PHP)
页面静态化 使用模板引擎 可以使用Smarty的缓存机制生成静态HTML缓存文件 $smarty->cachedir=$ROOT·"/cache"://缓存目录 $smart ...
- P1634 禽兽的传染病
题目背景 mxj的启发. 题目描述 禽兽患传染病了.一个禽兽会传染x个禽兽.试问n轮传染后有多少禽兽被传染? 输入输出格式 输入格式: 两个数x和n. 输出格式: 一个数:被传染的禽兽数. 输入输出样 ...
- Win7下安装Flash低版本
我把HKEY_LOCAL_MACHINE\SOFTWARE\Macromedia\FlashPlayer\SafeVersions中高于要装的版本的项目都删了,还是不行. 看了这个帖子后发现,原来64 ...
- Unity 脚本挂载位置
原则:谁的脚本,挂载到谁身上 1,一般场景中会有个GameController脚本,挂在空物体上. 2,我见很多人脚本习惯挂到Camera上,好吧,不知算不算规范.
- “肥宅快乐数”-python暴力版
编写一个函数来判断一个数是不是“快乐数”.一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1.如 ...
- Pyhton学习——Day6
# def test(x) : #形参:不占内存空间,调用函数时传入值,程序完成形参释放内存# # 注释内容# # 代码内容# y = x*2# print(y)# # return# # test( ...
- [置顶]
Elon Musk (伊隆·马斯克):无限的创想与意志的胜利
Elon Musk (伊隆·马斯克):无限的创想与意志的胜利 很多人说 Steve Jobs 很伟大,这一点我认同.但是,单纯从创造出的产物而言,Elon Musk 的成就毫无疑问远远超越 Steve ...
- HDU 2669 Romantic( 拓欧水 )
链接:传送门 题意:求解方程 X * a + Y * b = 1 的一组最小非负 X 的解,如果无解输出 "sorry" 思路:裸 exgcd /***************** ...
- js追加元素
直接运行 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- VUE:class与style强制绑定
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...