UVA 815

#include
#include
double a[2000];
int cmp( const void * a, const void *b)
{
    return ((*(double *) a - *(double*)b > 0)?1 : -1);
}
int main()
{
    int m, n, kase  = 0;
    while(scanf("%d %d", &n, &m)==2&&n)
    {
        int i,j;
        double vo;
        for( i = 0; i < n*m;i++)
        {
            scanf("%lf", &a[i]);

        }
        scanf("%lf",&vo);
        vo = vo/100;
        qsort(a,n*m,sizeof(a[0]),cmp);
        double avg, sum = 0;

        printf("Region %d\n",++kase);

      for(i = 0; i < n*m; i++)
        {
         sum +=a[i];
         avg  = (sum + vo)/(double)(i+1.0);
         if(a[i+1]>avg)
            break;
        }

        printf("Water level is %.2lf meters.\n",avg);
        if(i < n *m)
        printf("%.2lf ",100.0*(i+ 1)/(double)(n*m ));
        else
        printf("%.2lf ",100.0);
        printf("percent of the region is under water.\n\n");


    }
    return 0;
}

你可能感兴趣的:(UVA)