首页 > 代码库 > uva 815 - Flooded!(点名要做的思路题~我觉得方法挺好)

uva 815 - Flooded!(点名要做的思路题~我觉得方法挺好)

#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

uva 815 - Flooded!(点名要做的思路题~我觉得方法挺好)