2018_2_9_Flooded!_lower_bound+简单计算
2018-02-09 22:43
309 查看
Flooded!
DescriptionTo enable homebuyers to estimate the cost of flood insurance, a real-estate firm provides clients with the elevation of each 10-meter by 10-meter square of land in regions where homes may be purchased. Water from rain, melting snow, and burst water mains will collect first in those squares with the lowest elevations, since water from squares of higher elevation will run downhill. For simplicity, we also assume that storm sewers enable water from high-elevation squares in valleys (completely enclosed by still higher elevation squares) to drain to lower elevation squares, and that water will not be absorbed by the land.
From weather data archives, we know the typical volume of water that collects in a region. As prospective homebuyers, we wish to know the elevation of the water after it has collected in low-lying squares, and also the percentage of the region's area that is completely submerged (that is, the percentage of 10-meter squares whose elevation is strictly less than the water level). You are to write the program that provides these results.
InputThe input consists of a sequence of region descriptions. Each begins with a pair of integers, m and n, each less than 30, giving the dimensions of the rectangular region in 10-meter units. Immediately following are m lines of n integers giving the elevations of the squares in row-major order. Elevations are given in meters, with positive and negative numbers representing elevations above and below sea level, respectively. The final value in each region description is an integer that indicates the number of cubic meters of water that will collect in the region. A pair of zeroes follows the description of the last region. OutputFor each region, display the region number (1, 2, ...), the water level (in meters above or below sea level) and the percentage of the region's area under water, each on a separate line. The water level and percentage of the region's area under water are to be displayed accurate to two fractional digits. Follow the output for each region with a blank line. Sample Input3 3
25 37 45
51 12 34
94 83 27
10000
0 0
Sample OutputRegion 1
Water level is 46.67 meters.
66.67 percent of the region is under water.
SourceWorld Finals 1999#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int main(){
int n,m;
int z=1;
while(scanf("%d%d",&n,&m),n||m){
vector<int> v(n*m);
int len=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&v[len++]);
sort(v.begin(),v.end());
vector<int> t(len+1);
for(int i=1;i<=len;i++)
t[i]=t[i-1]+100*(v[i]-v[i-1])*i;
int w;
scanf("%d",&w);
int k=lower_bound(t.begin(),t.end(),w)-t.begin();
if(t[k]>w)k--;
w-=t[k];
double h=v[k]+w/(100.0*(k+1));
double p=100.0*((k+1)/1.0)/len;
printf("Region %d\n",z++);
printf("Water level is %.2lf meters.\n",h);
printf("%.2lf percent of the region is under water.\n\n",p);
}
}
Time Limit: 1000MS | Memory Limit: 30000K | |||
Total Submissions: 6716 | Accepted: 1965 | Special Judge |
From weather data archives, we know the typical volume of water that collects in a region. As prospective homebuyers, we wish to know the elevation of the water after it has collected in low-lying squares, and also the percentage of the region's area that is completely submerged (that is, the percentage of 10-meter squares whose elevation is strictly less than the water level). You are to write the program that provides these results.
InputThe input consists of a sequence of region descriptions. Each begins with a pair of integers, m and n, each less than 30, giving the dimensions of the rectangular region in 10-meter units. Immediately following are m lines of n integers giving the elevations of the squares in row-major order. Elevations are given in meters, with positive and negative numbers representing elevations above and below sea level, respectively. The final value in each region description is an integer that indicates the number of cubic meters of water that will collect in the region. A pair of zeroes follows the description of the last region. OutputFor each region, display the region number (1, 2, ...), the water level (in meters above or below sea level) and the percentage of the region's area under water, each on a separate line. The water level and percentage of the region's area under water are to be displayed accurate to two fractional digits. Follow the output for each region with a blank line. Sample Input3 3
25 37 45
51 12 34
94 83 27
10000
0 0
Sample OutputRegion 1
Water level is 46.67 meters.
66.67 percent of the region is under water.
SourceWorld Finals 1999#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int main(){
int n,m;
int z=1;
while(scanf("%d%d",&n,&m),n||m){
vector<int> v(n*m);
int len=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&v[len++]);
sort(v.begin(),v.end());
vector<int> t(len+1);
for(int i=1;i<=len;i++)
t[i]=t[i-1]+100*(v[i]-v[i-1])*i;
int w;
scanf("%d",&w);
int k=lower_bound(t.begin(),t.end(),w)-t.begin();
if(t[k]>w)k--;
w-=t[k];
double h=v[k]+w/(100.0*(k+1));
double p=100.0*((k+1)/1.0)/len;
printf("Region %d\n",z++);
printf("Water level is %.2lf meters.\n",h);
printf("%.2lf percent of the region is under water.\n\n",p);
}
}
相关文章推荐
- NNU_20161103_6PAT4-8 简单阶乘计算
- 计算子网地址和广播地址的简单公式
- POJ 1269 Intersecting Lines 简单计算几何
- Android手机软件开发简单计算功能一例
- [2002]:计算球体积(简单)
- Diffuse Light 的 简单计算版 PerPixel --第一个shader,简单点
- 华为上机练习题--简单加减表达式计算
- 夕拾算法进阶篇:6)简单计算器(stack)
- php简单计算年龄的方法(周岁与虚岁)
- Python简单实现基于VSM的余弦相似度计算
- Python简单实现基于VSM的余弦相似度计算
- [每天一个知识点]24-编程技巧-如何简单计算分页等需要进1的除法
- 一个简单方法完成C#时间间隔的计算
- 公历闰年的简单计算方法
- 简单计算字符串的高度
- 涨知识!从一个简单的消息服务,看云计算架构的真容
- [图解教程] Axis2与Eclipse整合开发Web Service之一:简单的计算服务例子
- 计算两个字符串之间是否包含的简单方法
- [hdu] 6167 简单计算几何