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
.
.
.
.
.
分析
二分平均值,对全图每个点减去平均值后,每次取某一列的最大值,看结果是否小于0
.
.
.
.
.
程序:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,h;
double a[100010],l=0,r=-2147483647,ans;
bool check(double mid)
{
double he=0;
for(int i=0;i<=n-1;i++)
{
double maxx=-21474836472,s=0;
for (int j=1;j<=h;j++)
{
s+=a[h*i+j];
maxx=max(s-j*mid,maxx);
}
he+=maxx;
}
return he>=0;
}
int main()
{
scanf("%d%d",&n,&h);
for (int i=0;i<n;i++)
for (int j=1;j<=h;j++)
{
scanf("%lf",&a[i*h+j]);
r=max(r,a[i*h+j]);
}
while (l+0.000001<r)
{
double he=0,mid=(l+r)/2;
if (check(mid)) l=mid; else r=mid-0.000001;
ans=mid;
}
printf("%.4lf",ans);
return 0;
}