您的位置:首页 > 其它

POJ-1887

2015-09-19 19:35 281 查看
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main(int argc, char *argv[]){
int m,n;
int index=0;
while(cin>>m>>n,m|n){
index++;
vector<int> v;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
int height;
cin>>height;
v.push_back(height);
//cout<<"add: "<<height<<endl;
}
}

sort(v.begin(),v.end());

int walterVolume;
cin>>walterVolume;

int sumLand=0;

int baseHeight=0;
int curHeight;
for(vector<int>::iterator iter=v.begin();iter!=v.end();++iter){
if(iter==v.begin()){
baseHeight=*iter;
curHeight=baseHeight;
sumLand++;

continue;
}

curHeight=*iter;

int addWalter=sumLand*(curHeight-baseHeight)*100;
if(addWalter>=walterVolume){
break;
}else{
walterVolume-=addWalter;
baseHeight=curHeight;
sumLand++;

//cout<<"walterVolume= "<<walterVolume<<endl;
}
}

float walterHeight=baseHeight+walterVolume*1.0/100/sumLand;
float persent=100*sumLand*1.0/v.size();

cout<<"Region "<<index<<endl;
printf("Water level is %0.2f meters.\n",walterHeight);
printf("%0.2f percent of the region is under water.\n",persent);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: