【習題 4-9 UVA - 815】Flooded!
阿新 • • 發佈:2018-11-02
【連結】 我是連結,點我呀:)
【題意】
在這裡輸入題意
【題解】
題目很迷啊。
不會出現盆地?
可以理解為一條線。
從左往右高度上升的一座座山。
然後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; }