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!的更多相关文章
随机推荐
- Ubuntu 12 修改当前用户密码:new password is too simple
修改当前登录用户的密码,通常使用如下命令: $ passwd Old password:****** New password:******* Re-enter new password:****** ...
- php 正则表达式的使用
要点:php正则表达式要用双引号,且要用“/ /”斜线做开始结束. 1.preg_match . preg_match_all 两者的区别:第一次匹配成功后就会停止匹配,如果要实现全部结果的匹配,即搜 ...
- int long 等基础类型在不同平台的大小
转自http://www.cnblogs.com/yishuiliunian/archive/2011/03/18/1988244.html 上次腾讯面试,问我int和long分别几个字节,结果被鄙视 ...
- android Home键和返回键
在Android中,当按下Home键,默认情况下stop前台的actiity,即activity设置成onstop,而不是ondestory.如果再次启动该activity不是调用onCreate,而 ...
- Spring mvc 报错:No qualifying bean of type [java.lang.String] found for dependency:
具体错误: No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean w ...
- Gunicorn 问题
Does Gunicorn suffer from the thundering herd problem? The thundering herd problem occurs when many ...
- [Asp.net MVC]Asp.net MVC5系列——添加数据
目录 概述 显示添加数据时所用表单 处理HTTP-POST 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5系列 ...
- 一起入门python5之for循环
昨天中午本来写了的,结果手贱了一下ctrl+x以后又去复制了别的东西.结果所有写的都没有了.蛋疼.继续写吧.今天来说for循环即条件判断>>> age = 20 #首先 ...
- 【SpringBoot】SpringBoot 入门示例
参考资料: http://www.tuicool.com/articles/mqeee2A http://www.cnblogs.com/suncj/p/4065589.html http://spr ...
- MVC Create
本文介绍如何在MVC里往数据库中插入新的记录. 这里用到的数据表如下: Employees Step 1: 在Control文件里加入method public ActionResult Create ...