POJ 2029 Get Many Persimmon Trees (标记)

给一个长宽已知的矩形,要求围起最多的树。数据量只有100*100,标记树的位置,暴力枚举所有的矩形找最大值就可以了

//Memory: 188 KB		
//Time: 0 MS
#include <stdio.h>
#include <string.h>
bool map[101][101];
int max(int a,int b)
{
	return a>b?a:b;
}
int main()
{
	int n,w,h,s,t;
	while(~scanf("%d",&n) && n)
	{
		int i,j,x,y,sum=0,maxx=0;
		memset(map,0,sizeof(map));
		scanf("%d %d",&w,&h);
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&x,&y);
			map[x][y]=true;
		}
		scanf("%d %d",&s,&t);
		y=0;
		for(i=1;i<=w-s+1;i++)
		{	
			for(j=1;j<=h-t+1;j++)
			{
				if(y==i)
				{
					for(x=i;x<=i+s-1;x++)
					{
						if(map[x][j-1])
							sum--;
						if(map[x][j+t-1])
							sum++;
					}				
				}
				else
				{
					sum=0;
					for(x=i;x<=i+s-1;x++)
						for(y=j;y<=j+t-1;y++)
							if(map[x][y])
								sum++;
					y=i;
				}
				maxx=max(maxx,sum);
			}
		}
		printf("%d\n",maxx);
	}
	return 0;
}


你可能感兴趣的:(POJ 2029 Get Many Persimmon Trees (标记))