Cod sursa(job #1295412)

Utilizator dr_personalityEftime Andrei Horatiu dr_personality Data 19 decembrie 2014 14:12:12
Problema Balans Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <iomanip>
#include<fstream>
using namespace std;
ifstream in("balans.in");
ofstream out("balans.out");

const int nmax = 305;
int m, n, mat[nmax][nmax], p, q;
double rasp;
 
int main() {
    int player_unu=0;

    in>>m>>n>>p>>q;
    for(int i = 1; i <= m * 2; i++)
	{
        for(int j = 1; j <= n * 2; j++)
		{
            if(i<=m && j<=n)
			{
                in>>mat[i][j];
                mat[m + i][j] = mat[i][j + n] = mat[i + m][j + n] = mat[i][j];
            }

            mat[i][j] += mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
        }
	}

    for(int h = p; h<=m; h++)
        for (int b = q; b<=n; ++b)
            for (int i = m + 1; i <= m * 2; ++i)
                for (int j = n + 1; j <= n * 2; ++j)
                    if (rasp * h * b < mat[i][j] + mat[i - h][j - b] - mat[i][j - b] - mat[i - h][j])
                        rasp = 1.0 * (mat[i][j] + mat[i - h][j - b] - mat[i][j - b] - mat[i - h][j]) / (h * b);

    out<<setprecision(3)<<fixed;
	out<<rasp<<'\n';

	return player_unu;
}