|
- #include<iostream>
- #include<algorithm>
- #include<cstdio>
- using namespace std;
- int m,n,V,t=1;
- double a[1000],v,l,r,mid,cnt,ans;
- double const eps=1e-3;
- int main()
- {
- cin>>m>>n;
- while(m&&n)
- {
- l=r=999999.0;
- for(int i=1;i<=m*n;i++)cin>>a[i],l=min(l,a[i]);
- cin>>V;
- v=V/100.0;
- sort(a+1,a+m*n+1);
- while(r-l>eps)
- {
- mid=(l+r)/2.0;
- cnt=0.0;
- for(int i=1;i<=m*n&&mid-a[i]>eps;i++)cnt+=mid-a[i];
- if(cnt-v>=eps)r=mid-eps,ans=mid;
- else l=mid+eps;
- }
- int k=1;
- while(k<m*n&&a[k]-ans<eps)k++;
- k--;
- printf("Region %d\n",t++);
- printf("Water level is %.2f meters.\n",ans);
- printf("%.2f percent of the region is under water.\n",100*k/(1.0*m*n));
- cin>>m>>n;
- }
- return 0;
- }
复制代码 |
|