UVa815_Flooded!
#include <iostream>
//#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; const int maxn = * + ;
const int space = * ; int main()
{
//ofstream out("out.txt");
int m, n, kase = , volume; //降水总量
double eleva[maxn], height; //每个格子的海拔高度, 输入的高度
double percnt = ; //有多少百分比的区域
while (cin >> m >> n)
{
memset(eleva, , sizeof(eleva));
if (!m && !n) break;
for (int i = ; i < m; i++)
{
for (int j = ; j < n; j++)
{
cin >> height;
eleva[i * n + j] = height;
}
}
cin >> volume;
sort(eleva, eleva + m*n); //排序 int k, comput = ; //计算已经淹没地区的水量
for (k = ; k < m*n; k++)
{
int tmp = comput + (eleva[k] - eleva[k - ]) * space * k;
if (tmp >= volume)
break;
comput = tmp;
}
double water = (volume - comput) / (double)(k * space) + eleva[k - ]; //最终水平面高度是 = 当前被淹没的最高海拔 + 水面比当前海拔高出的高度 cout << "Region " << ++kase << "\n";
cout << fixed << setprecision()
<< "Water level is " << water << " meters.\n"; double total = m*n;
percnt = (k*100.0 / total) ; //被淹没区域比例 = 当前比水平面低的海拔数 / 区域总数 cout << fixed << setprecision()
<< percnt << " percent of the region is under water.\n\n";
} return ;
}
如图,将海拔按高矮排序好(先排序好,比较容易计算已经淹没地区的水量),由于是水往地处流,如果水量如图,淹没区域如图中阴影地区。UVa815_Flooded!的更多相关文章
随机推荐
- Sublime多行编辑快捷键
鼠标选中多行,按下 Ctrl Shift L (Command Shift L) 即可同时编辑这些行: 鼠标选中文本,反复按 CTRL D (Command D) 即可继续向下同时选中下一个相同的文本 ...
- MyEclipse 自动提示设置
window --> Perferences--> General--> keys Content Assist默认的是Ctrl +space Content Assist快捷键设置 ...
- scanf函数与输入缓冲区
本文链接:http://www.cnblogs.com/xxNote/p/4008668.html 今天看书的时候遇到scanf函数与缓冲区的问题,产生了一些猜想即:应该有一个指针来记录缓冲区中读取到 ...
- 实现Android的不同精度的定位(基于网络和GPS)
解决方案: 实现Android的不同精度的定位(基于网络和GPS) Android中的定位服务的相关类基本上都在android.location包中,其中位置服务管理器(LocationManager ...
- mysql workbench建表时PK,NN,UQ,BIN,UN,ZF,AI
1. [intrinsic column flags] (基本字段类型标识) - PK: primary key (column is part of a pk) 主键 - NN: not null ...
- trigger() & bind() 使用心得
trigger(type) 在每一个匹配的元素上触发某类事件. 返回值:jQuery 参数: type (String): 要触发的事件类型 示例: $("p").trigger( ...
- [codevs1380]没有上司的舞会([BZOJ2060][Usaco2010 Nov]Visiting Cows 拜访奶牛)
[codevs1380]没有上司的舞会 试题描述 Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现 ...
- BZOJ 2177: 曼哈顿最小生成树
Sol 考了好几次曼哈顿最小生成树,然而一直不会打...这次终于打出来了...神tm调试了2h...好蛋疼... 首先曼哈顿最小生成树有个结论就是讲它每45度分出一个象限,对于每个点,只与每个象限中离 ...
- 2 GPS utility methods
Methond 1 is to check whether the GPS is on: 1 2 3 4 5 public boolean isGPSIsOn() { LocationManager ...
- Python自动化之异常处理
1 异常基本结构 try: pass except Exception,ex: pass 2 异常种类 AttributeError 试图访问一个对象没有的树形,比如foo.x,但是foo没有属性x ...