#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; double a[100000]; double vol[100000]; int m,n; double v1,v2; bool cmp(double aa,double bb) { if(aa>bb) return true; } int main() { int kase=0; while(scanf("%d%d",&m,&n)!=EOF) { kase++; if(m==0&&n==0) break; v1=0; double temp; for(int i=0;i<m*n;i++) { cin>>temp; vol[i]=temp*100; v1+=vol[i]; a[i]=temp; } sort(a,a+m*n,cmp); sort(vol,vol+m*n,cmp); cin>>v2; double v=v1+v2; double height; int r=m*n; for(int i=0;i<m*n;i++) { double area=(m*n-i)*100; double temp1=v/area; if(temp1>a[i]) { height=temp1; break; } else { v=v-a[i]*100; r--; } } printf("Region %d\n",kase); printf("Water level is %.2lf meters.\n",height); printf("%.2lf percent of the region is under water.\n\n",(r+0.0)/(m*n)*100); } return 0; }
应该很好理解,自己看吧O(∩_∩)O
时间: 2024-10-06 11:52:17