当前位置: 代码迷 >> 综合 >> UVA 815 Flooded!
  详细解决方案

UVA 815 Flooded!

热度:48   发布时间:2023-09-23 09:54:01.0

先sort一下,在计算出相邻高度差,再依次计算蓄水量 

如案例中,13*100+2*200+7*300......

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
#define maxn 1000
int main()
{int m,n,kase=0;while(scanf("%d%d",&m,&n)==2&&m){int R[maxn]={0},w;for(int i=0;i<m*n;i++)scanf("%d",&R[i]);scanf("%d",&w);sort(R,R+m*n);int high=R[0];for(int i=0;i<m*n-1;i++) R[i]=R[i+1]-R[i];int sum=0,cnt=1;for(int i=0;i<m*n-1;i++,cnt++) <span style="white-space:pre">	</span>if(sum+R[i]*cnt*100>w) break;<span style="white-space:pre">	</span>else sum+=R[i]*cnt*100,high+=R[i];printf("Region %d\n",++kase);printf("Water level is %.2f meters.\n",(double)(w-sum)/(cnt*100)+high);printf("%.2f percent of the region is under water.\n\n",((double)cnt/(m*n))*100);}
}