UVA - 815 Flooded!

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_42623428/article/details/82987036

模拟一下

#include <bits/stdc++.h>
using namespace std;
#define MAXN 900

int main()
{
    int a[MAXN];
    double sum,h,ev;
    int cases=0,n,m,po,t;
    while(cin>>n>>m&&n)
    {
        for(int i=1;i<=n*m;i++)
            cin>>a[i];
        cin>>sum;
        sum/=100;
        for(int i=1;i<n*m;i++)
        {
            t=i;
            for(int j=i+1;j<=n*m;j++)
                if(a[j]<a[t]) t=j;
            if(t!=i)
            {
                int tmp=a[i];
                a[i]=a[t];
                a[t]=tmp;
            }
        }
        for(int i=2;i<=n*m;i++)
        {
            po=(a[i]-a[i-1])*(i-1);
            if(sum>=po)
            {
                sum-=po;
            }
            else
            {
                h=a[i-1]+sum/(i-1);
                sum=0;
                ev=(i-1)*1.0/n/m;
                break;
            }
        }
        if(sum)
        {
            h=a[n*m]+sum/n/m;
            ev=1;
        }
        printf("%d\n",++cases);
        cout<<"Region "<<++cases<<endl;
        printf("Water level is %.2lf meters.\n",h);
        printf("%.2lf percent of the region is under water.\n\n",ev*100);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42623428/article/details/82987036