【习题 4-9 UVA

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

题目很迷啊。 不会出现盆地? 可以理解为一条线。 从左往右高度上升的一座座山。 然后V升的水从最左边的山倒进去。 然后问你最后海拔多高。。 (为什么是这样啊??? 鬼知道。。。 所以每次只要看看前i个山同时升高a[i+1]-a[i]是不是小于等于rest就好。 小于等于的话。就能持续升高。

【代码】

#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std;

const int N = 1000;

int n,m;
int a[N+10];
double rest;

int main(){
    //freopen("/home/ccy/rush.txt","r",stdin);
    //freopen("/home/ccy/rush_out.txt","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0);
    int kase = 0;
    while (cin >> n >> m){
        if (n==0 && m==0) break;
        cout<<"Region "<<++kase<<endl;
        int cnt = 0;
        rep1(i,1,n)
            rep1(j,1,m)
                cin >> a[++cnt];
        cin >> rest;
        rest/=100;
        sort(a+1,a+1+cnt);
        double ans1,ans2;
        rep1(i,1,cnt){
            if (i==cnt){
                ans1 = a[i]+rest/(1.0*i);
                ans2 = 1;
            }else{
                if (1LL*(a[i+1]-a[i])*i<=rest){
                    rest-=1LL*(a[i+1]-a[i])*i;
                }else{
                    ans1 = a[i]+rest/(1.0*i);
                    ans2 = 1.0*i/cnt;
                    break;
                }
            }
        }
        cout<<"Water level is "<<fixed<<setprecision(2)<<ans1<<" meters."<<endl;
        cout<<fixed<<setprecision(2)<<ans2*100.0<<" percent of the region is under water."<<endl;
        cout<<endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/AWCXV/p/9894326.html