Pagini recente » Cod sursa (job #2902620) | Cod sursa (job #2880020) | Cod sursa (job #1053327) | Cod sursa (job #1267984) | Cod sursa (job #918663)
Cod sursa(job #918663)
#include <fstream>
#include <iostream>
#include <cstring>
#include <deque>
#include <algorithm>
#include <numeric>
#include <limits>
#include <iterator>
#define MAX_SIZE 305
using namespace std;
typedef deque<pair<long long, short> > BalansDeq;
static const long long MinLongLong = numeric_limits<long long>::min();
static long long mat[MAX_SIZE][MAX_SIZE];
static long long subArray[MAX_SIZE];
void PushIntoDeq(BalansDeq& deq, long long val, short pos)
{
while (!deq.empty() && deq.back().first >= val)
{
deq.pop_back();
}
deq.push_back(make_pair(val, pos));
}
int main()
{
int N, M, R, C;
fstream fin("balans.in", fstream::in);
fstream fout("balans.out", fstream::out);
float flMaxBalans = 0.0f;
fin >> N >> M >> R >> C;
//cout << N << " " << M << " " << R << " " << C << endl;
if (R == 0)
{
R = 1;
}
if (C == 0)
{
C = 1;
}
for (int i=1; i<=N; ++i)
{
for (int j=1; j<=M; ++j)
{
fin >> mat[i][j];
mat[i+N][j] = mat[i][j];
mat[i][j+M] = mat[i][j];
mat[i+N][j+M] = mat[i][j];
}
}
/*for (int i=1; i<=2*N; ++i)
{
for (int j=1; j<=2*M; ++j)
{
cout << mat[i][j] << " ";
}
cout << endl;
}*/
for (int i=1; i<=2*N; ++i)
{
for (int j=1; j<=2*M; ++j)
{
mat[i][j] = mat[i][j] + mat[i-1][j] + mat[i][j-1] - mat[i-1][j-1];
}
}
for (int r=R; r<=N; ++r)
{
for (int c=C; c<=M; ++c)
{
for (int i=r; i<=2*N-r; ++i)
{
for (int j=c; j<=2*M-c; ++j)
{
long long sum = mat[i][j] - mat[i-r][j] - mat[i][j-c] + mat[i-r][j-c];
flMaxBalans = max(flMaxBalans, (float)sum / (r*c));
}
}
}
}
fout.precision(3);
fout << fixed << flMaxBalans << "\n";
return 0;
}