题目
Description
Input
Output
Sample Input
4 3
4 3 3
5 1 6
2 6 1
3 2 9
Sample Output
4.4286
Data Constraint
Hint
分析
CODE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m;
double a[100010];
int main(){
scanf("%d%d",&n,&m);
for (int i=1;i<=n*m;i++)
scanf("%lf",&a[i]);
double l=0.0,r=1000000000.0;
while(r-l>0.00001){
double mid=(l+r)/2.0,sum=0;
for (int i=1;i<=n;i++){
double k=-1000000000;
double s=a[(i-1)*m+1];
for (int j=1;j<=m;j++){
k=max(k,s-j*mid);
s+=a[(i-1)*m+j+1];
}
sum+=k;
}
if(sum<0) r=mid;
else l=mid;
}
printf("%.4lf",l);
return 0;
}