【UVA】815 - Flooded!

水题,排序之后依次累加,模拟。

14069284 815 Flooded! Accepted C++ 0.032 2014-08-20 10:42:17

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<string>
#include<sstream>
#include<ctime>
using namespace std;
#define _PI acos(-1.0)
#define esp 1e-9
#define INF 1 << 30
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pill;
/*===========================================
===============KinderRiven===================
===========================================*/
#define MAXD 1000 + 10
int n,m;
int main(){
    int Case = 1;
    while(scanf("%d%d",&n,&m)){
        if(!n && !m)
            break;
        double array[MAXD],V;
        n = n * m;
        for(int i = 0 ; i < n ; i ++)
            scanf("%lf",&array[i]);
        scanf("%lf",&V);
        V /= 100;
        sort(array, array + n);
        int area = 0;
        while(V){
            int i,j;
            for(i = 0 ; i < n - 1; i ++){
                 if(array[i] < array[i + 1])
                    break;
            }
            area = i + 1;
            if(i == n - 1){
                double aver = V / n;
                V = 0;
                for(j = 0 ; j < n ; j++)
                    array[j] += aver;
            }
            else{
                double _V = (array[i + 1] - array[i]) * (i + 1);
                if(_V > V)
                    _V = V;
                V -= _V;
                double aver = _V / (i + 1);
                for(j = 0 ; j <= i ; j++)
                    array[j] += aver;
            }
        }
        printf("Region %d\n",Case++);
        printf("Water level is %.2f meters.\n",array[0]);
        printf("%.2f percent of the region is under water.\n",1.0 * area / n * 100);
        printf("\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值