How to solve this problem -- and what's wrong with my code?
Posted by
Li, Yi 2 Nov 2001 17:58
#include <stdio.h>
int l, m, n, min, max;
int land[100][4];
int getmax(int x, int y)
{
int k, maxx;
maxx = 1;
for (k = 0; k <= m; k++)
{
if (x + l <= land[k][2] || y + l <= land[k][3] || x >=
land[k][2] + land[k][1] || y >= land[k][3] + land[k][1])
continue;
else
{
if (land[k][0] > 100)
return 256;
else
if (land[k][0] > maxx)
maxx = land[k][0];
}
}
return maxx;
}
void main()
{
int i, j, p, q, r, s;
scanf("%d%d", &n, &l);
n--;
scanf("%d", &m);
m--;
for (i = 0; i <= m; i++)
{
scanf("%d%d%d%d", &p, &q, &r, &s);
r--;
s--;
land[i][0] = p;
land[i][1] = q;
land[i][2] = r;
land[i][3] = s;
}
min = 255;
for (i = 0; i <= n - l; i++)
{
for (j = 0; j <= n - l; j++)
{
max = getmax(i, j);
if (max < min) min = max;
}
}
if (min > 100) printf("IMPOSSIBLE\n"); else printf("%
d\n", min);
}