# Cod sursa(job #4740)

Utilizator Data 6 ianuarie 2007 19:18:25 Balans 25 cpp done Arhiva de probleme 1.15 kb
``````#include <cstdio>

const int NMAX = 151;

int N, M, R, C;
int A[NMAX][NMAX];
unsigned S[NMAX << 1][NMAX << 1];
int s, c;

FILE *fin = fopen("balans.in", "rt");
int i, j;

fscanf(fin, " %d %d %d %d", &N, &M, &R, &C);

for (i = 1; i <= N; ++i)
for (j = 1; j <= M; ++j)
fscanf(fin, " %d", &A[i][j]);

fclose(fin);
}

void prepare() {
int i, j;

for (i = 1; i <= (N << 1); ++i)
for (j = 1; j <= (M << 1); ++j)
S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] +
A[i > N ? i - N : i][j > M ? j - M : j];
}

void brute() {
int i, j, k, l, t;
unsigned aux;

s = 0; c = 1;

for (i = 1; i <= N; ++i)
for (j = 1; j <= M; ++j)
for (k = R - 1; k < N; ++k)
for (l = C - 1; l < M; ++l) {
aux = S[i + k][j + l] - S[i + k][j - 1] - S[i - 1][j + l] + S[i - 1][j - 1];
t = (k + 1) * (l + 1);
if ((long long) s * t < (long long) c * aux)
printf("%d %d %d %d => %d %d\n", i, j, k, l, aux, t),
s = aux, c = t;
}
}

void write() {
FILE *fout = fopen("balans.out", "wt");

fprintf(fout, "%.3lf\n", (double) s / c);

fclose(fout);
}

int main() {