Cod sursa(job #1232039)

Utilizator tudorv96Tudor Varan tudorv96 Data 21 septembrie 2014 22:07:57
Problema Balans Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <fstream>
#include <iomanip>
using namespace std;

ifstream fin ("balans.in");
ofstream fout ("balans.out");

const int N = 305;

int m, n, a[N][N], sp[N][N], p, q;
double sol;

int main() {
    fin >> m >> n >> p >> q;
    for (int i = 1; i <= m; ++i)
        for (int j = 1; j <= n; ++j) {
            fin >> a[i][j];
            a[m + i][j] = a[i][j + n] = a[i + m][j + n] = a[i][j];
        }
    for (int i = 1; i <= m * 2; ++i)
        for (int j = 1; j <= n * 2; ++j)
            sp[i][j] = sp[i][j-1] + sp[i-1][j] - sp[i-1][j-1] + a[i][j];
    for (int i = m; i <= m * 2; ++i)
        for (int j = n; j <= n * 2; ++j)
            for (int a = p; a <= m; ++a)
                for (int b = q; b <= n; ++b)
                        sol = max(sol, 1.0 * (sp[i][j] + sp[i-a][j-b] - sp[i][j-b] - sp[i-a][j]) / (a * b));
    fout << fixed << setprecision(3) << sol;
}