Cod sursa(job #2594549)

Utilizator alex_benescubenescu alexandru alex_benescu Data 6 aprilie 2020 12:31:11
Problema Balans Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <cstdio>
using namespace std;
int S[303][303];
int i,j,N,M,X,R,C,line,column;
double MAX;
int main(){
freopen("balans.in","r",stdin);
freopen("balans.out","w",stdout);
scanf("%d%d%d%d",&N,&M,&R,&C);
for (i=1;i<=2*N;++i)
for (j=1;j<=2*M;++j){
  if (i<=N && j<=M){
    scanf("%d",&S[i][j]);
    S[i+N][j]=S[i][j+M]=S[i+N][j+M]=S[i][j];
  }
  S[i][j]=S[i][j]+S[i][j-1]+S[i-1][j]-S[i-1][j-1];
}
for (line=R;line<=N;++line)
for (column=C;column<=M;++column)
for (i=N+1;i<=2*N;++i)
for (j=M+1;j<=2*M;++j)
if ((S[i][j]-S[i-line][j]-S[i][j-column]+S[i-line][j-column])>MAX*line*column)
MAX=1.0*(S[i][j]-S[i-line][j]-S[i][j-column]+S[i-line][j-column])/(line*column);
printf("%.3f",((int)(MAX*1000))/1000.0);
return 0;
}