Pagini recente » Cod sursa (job #1062605) | Cod sursa (job #3204910) | Cod sursa (job #2641521) | Cod sursa (job #1078352) | Cod sursa (job #2660348)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream fin("balans.in");
ofstream fout("balans.out");
int w, h, mw, mh;
double ma[341][341];
void read(){
fin >> h >> w >> mh >> mw;
for(int y = 1; y <= h; ++y){
for(int x = 1; x <= w; ++x){
fin >> ma[x][y];
ma[x+w][y+h] = ma[x][y+h] = ma[x+w][y] = ma[x][y];
}
}
}
void thesume(){
int h2=h+h, w2=w+w;
for(int y = 1; y <= h2; ++y){
for(int x = 1; x <= w2; ++x){
ma[x][y] += ma[x][y-1]+ma[x-1][y]-ma[x-1][y-1];
}
}
}
double kalk(int x1, int y1, int x2, int y2){
return ma[x2][y2] + ma[x1-1][y1-1]
- ma[x1-1][y2] - ma[x2][y1-1];
}
double ans = 0;
void solve(){
thesume();
for(int y = 1; y <= h; ++y){
for(int x = 1; x <= w; ++x){
for(int dh = mh; dh <= h; ++dh){
for(int dw = mw; dw <= w; ++dw){
ans = max(ans, kalk(x,y,x+dw-1,y+dh-1)/double(dw*dh));
}
}
}
}
}
int main(){
// ios_base::sync_with_stdio(false);
read();
solve();
fout << fixed << setprecision(3);
fout << ans;
return 0;
}