33,008
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#define MAXN 1010
#define MAXINT 0x7FFFFFFF
int n, m, g;
int a[MAXN][MAXN], b[MAXN][MAXN], c[MAXN][MAXN], d[MAXN][MAXN];
int bestc, bestr, bestx, besty;
int main(){
int i, j;
while (scanf("%d %d %d", &n, &m, &g)!=EOF){
bestc = 0;
for (i=0; i<n; ++i)
for (j=0; j<m; ++j){
scanf("%d", &a[i][j]);
if (a[i][j]) {
b[i][j] = i ? b[i-1][j]+1 : 1;
} else {
b[i][j] = 0;
}
if (b[i][j] >= g){
c[i][j] = 1;
d[i][j] = b[i][j];
if (j) {
c[i][j] += c[i][j-1];
if (d[i][j-1] < d[i][j])
d[i][j] = d[i][j-1];
}
if (c[i][j] > bestc || c[i][j] == bestc && d[i][j] > bestr){
bestc = c[i][j];
bestr = d[i][j];
bestx = i - bestr + 1;
besty = j - bestc + 1;
}
} else {
c[i][j] = 0;
d[i][j] = MAXINT;
}
}
if (bestc == 0)
puts("impossible");
else
printf("x=%d, y=%d, r=%d, c=%d\n", bestx, besty, bestr, bestc);
}
}