现在的位置: 首页 > 综合 > 正文

UVA – 815 Flooded

2018年03月17日 ⁄ 综合 ⁄ 共 776字 ⁄ 字号 评论关闭

只需要对所有的单位square升序排序,从第一个开始往上添水即可;

#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 10000000
using namespace std;
typedef long long LL;

const int maxn = 910;
double a[maxn];
int main()
{
    int kase=1,n,m;
    while(scanf("%d %d",&n,&m)==2){
        if(!n&&!m) break;

        int kk=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                scanf("%lf",&a[kk++]);
        sort(a,a+kk);

        double L;
        scanf("%lf",&L); L/=100;

        bool flag=false;
        double zen=0,posi,percentage;
        for(int i=1;i<kk;i++){
            double add=(a[i]-a[i-1])*i;
            if(zen+add>L){
                posi=((L-zen)/i)+a[i-1];
                percentage=(i*1.0)/kk;
                flag=true;
                break;
            }
            else zen+=add;
        }
        if(!flag){
            posi=((L-zen)/kk)+a[kk-1];
            percentage=1;
        }
        printf("Region %d\n",kase++);
        printf("Water level is %.2lf meters.\n",posi);
        printf("%.2lf percent of the region is under water.\n\n",percentage*100);
    }
    return 0;
}

抱歉!评论已关闭.