zoj 1716 Get Many Persimmon Trees

//这题主要是给定一个矩形的宽度和高度,在给出的这个矩形的面积中,
//求出包含最多的树的数目,最开始WA了很多次,因为没有考虑到取值的范围!
//下面主要用枚举的方法,一个一个的矩形进行枚举!
#include "iostream"
#include "memory.h"
#include "algorithm"
using namespace std;

struct treespos
{
	int width;
	int height;
};

int main()
{
	int treesnum, i, j, k, width, height, x, y, tempx, tempy, count;
	treespos pos[10001];//树木的坐标,由于之前开数组开小了,WA了一次!
	int ans[10001];//统计每一个矩形中包含树的数目!
	while (cin >> treesnum && treesnum)
	{
		cin >> width >> height;
		for (i = 0; i < treesnum; i++)
			cin >> pos[i].width >> pos[i].height;
		cin >> x >> y;
		memset(ans, 0, sizeof(ans));
		count = 0;
		for(i = 1; i <= width - x + 1; i++)//进行枚举,注意取值的范围,不要越界!
			for (j = 1; j <= height - y + 1; j++)
			{
				tempx = x+i-1;
				tempy = y+j-1;
				for(k = 0; k < treesnum; k++)
				{
					if (pos[k].width >=  i && pos[k].width <= tempx && pos[k].height <= tempy && pos[k].height >= j)
						ans[count]++;
				}
				count++;
			}
		sort(ans, ans+10001);
		cout << ans[10000] << endl;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值