您的位置:首页 > 其它

zoj 1716 Get Many Persimmon Trees

2012-04-01 10:41 477 查看
//这题主要是给定一个矩形的宽度和高度,在给出的这个矩形的面积中,
//求出包含最多的树的数目,最开始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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: