POJ 2029 Get Many Persimmon Trees (枚举)

网友投稿 212 2022-09-16

POJ 2029 Get Many Persimmon Trees (枚举)

Description

Input

The input consists of multiple data sets. Each data set is given in the following format. N W H x1 y1 x2 y2 … xN yN S T N is the number of persimmon trees, which is a positive integer less than 500. W and H are the width and the height of the entire field respectively. You can assume that both W and H are positive integers whose values are less than 100. For each i (1 <= i <= N), xi and yi are coordinates of the i-th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= xi <= W and 1 <= yi <= H, and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, S and T are positive integers of the width and height respectively of the estate given by the lord. You can also assume that 1 <= S <= W and 1 <= T <= H. The end of the input is indicated by a line that solely contains a zero.

Output

For each data set, you are requested to print one line containing the maximum possible number of persimmon trees that can be included in an estate of the given size.

Sample Input

1610 82 22 52 73 33 84 24 54 86 46 77 57 88 18 49 610 34 386 41 22 12 43 44 25 36 16 23 20

Sample Output

43

题意

给出一张地图,以及所有树的位置,然后给出矩形的大小,问地图中可以被这个矩形最多圈进多少棵树。

思路

考虑到数据范围比较小的关系,所以直接枚举即可。

​​sum[i][j]​​​ 代表从 ​​(1,1)​​​ 到 ​​(i,j)​​ 范围内树的个数。

所以利用这个便可以求得地图中任意矩形的权值啦!

输入矩形大小,枚举,找最大值即可。

AC 代码

#include #include#include#include#include#include#includeusing namespace std;#define INF (1<<25)int sum[105][105],data[105][105],ans;int get(int a,int b,int x,int y) //获取 (a,b) 到 (x,y) 矩形中树的个数{ return sum[x][y]-sum[x][b-1]-sum[a-1][y]+sum[a-1][b-1];}int main(){ int N,W,H,x,y; while(~scanf("%d",&N)&&N) { scanf("%d%d",&W,&H); ans=0; memset(sum,0,sizeof(sum)); memset(data,0,sizeof(data)); for(int i=0; i

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:HDU 4907 Task schedule (技巧)
下一篇:POJ 3041 Asteroids (最小点覆盖)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~