Cod sursa(job #2660349)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 18 octombrie 2020 23:35:40
Problema Balans Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>

using namespace std;

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

typedef long double triple;

int w, h, mw, mh;
triple 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];
		}
	}
}

triple 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];
}

triple 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)/triple(dw*dh));
				}
			}
		}
	}
}

int main(){
	// ios_base::sync_with_stdio(false);
	read();
	solve();
	fout << fixed << setprecision(3);
	fout << ans;
	return 0;
}