码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-07-21 11:43:45      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:uva

#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!(点名要做的思路题~我觉得方法挺好)

标签:uva

原文地址:http://blog.csdn.net/u013382399/article/details/38010077

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!