UVa815洪水Flooded!

Description

To 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.

Input

The 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.

Output

For 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 Input

3 3
25 37 45
51 12 34
94 83 27
10000
0 0

Sample Output

Region 1
Water level is 46.67 meters.
66.67 percent of the region is under water.

有一个n×m的网格,每个格子是边长10米的正方形,网格四周是无限大的墙壁。输入每个格子的海拔高度,以及网格内雨水的总体积。输出水位的海拔高度以及有多少百分比的区域有水(即高度严格小于水平面)。
 1 #include <iostream>
 2 #include <algorithm>
 3 #include<iomanip>
 4 int main()
 5 {
 6     using namespace std;
 7     int n, m;
 8     int hai[30 * 30];
 9     cin >> n >> m;
10     for (int i = 0; i < m*n; i++)
11         cin >> hai[i];
12     sort(hai, hai + m*n);            //排序,将输入的海拔高度从小到大排列
13     int T;
14     int k;
15     int h;
16     cin >> T;
17     for (int i = 0; i < n*m; i++)
18     {
19         T = T + 100*hai[i];            //将洪水总体积与 单个格子内海拔总体积 相加。
20
21         k = T / (100.0 * (i + 1));     //T 除以 (块数×面积)得到 平均海拔
22
23         if (k <= hai[i + 1])                     //加等号!!!!
24         {                                          //k<下一块格子的海拔,说明洪水只能淹没到这块格子
25             h = i;
26
27             break;
28         }
29     }
30     cout << "水位海拔:" << k << endl;
31
32     cout << fixed << setprecision(2) << (((h+1)*1.0) / (n*m))*100 << "%的区域里有水" << endl;
33     system("pause");
34     return 0;
35
36
37 }

#include<iomanip.h>

cout<<setiosflags(ios::fixed)<<setprecision(n);n即为小数点位数
时间: 2024-11-05 11:44:57

UVa815洪水Flooded!的相关文章

算法竞赛入门经典 第四章

[√ ] UVA1339 古老的密码 Ancient Cipher [√ ] UVA489 刽子手的游戏 Hangman Judge [√ ] UVA133 救济金发放 The Dole Queue [√ ] UVA213 信息解码 Message Decoding [√ ] UVA512 追踪电子表格中的单元格 Spreadsheet Tracking [√ ] UVA12412 师兄帮帮忙 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

UVA815(洪水)。

关键就是给海拔排个序,找出有多少快地低于水平面. 要注意n=m=1的情况,和100%的情况. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <string> 5 #include <vector> 6 #include <cctype> 7 #include <cstring> 8 #include <algorit

刷题记录--UVa815 Flooded!

这道题放在紫书最后一道,我以为挺难的,没想到挺简单的. 怎么一直不给结果,不等了,先睡了,明天再起来看. #include<cstdio> #include<iostream> #include<algorithm> using namespace std; int main(){ int m,n,kase=0; double total; while(scanf("%d%d",&m,&n)==2&&m!=0){ pr

扯谈网络编程之Tcp SYN flood洪水攻击

简介 TCP协议要经过三次握手才能建立连接: (from wiki) 于是出现了对于握手过程进行的攻击.攻击者发送大量的FIN包,服务器回应(SYN+ACK)包,但是攻击者不回应ACK包,这样的话,服务器不知道(SYN+ACK)是否发送成功,默认情况下会重试5次(tcp_syn_retries).这样的话,对于服务器的内存,带宽都有很大的消耗.攻击者如果处于公网,可以伪造IP的话,对于服务器就很难根据IP来判断攻击者,给防护带来很大的困难. 攻与防 攻击者角度 从攻击者的角度来看,有两个地方可以

[POI2007]洪水pow 题解

[POI2007]洪水pow 时间限制: 5 Sec  内存限制: 128 MB 题目描述 AKD市处在一个四面环山的谷地里.最近一场大暴雨引发了洪水,AKD市全被水淹没了.Blue Mary,AKD市的市长,召集了他的所有顾问(包括你)参加一个紧急会议.经过细致的商议之后,会议决定,调集若干巨型抽水机,将它们放在某些被水淹的区域,而后抽干洪水.你手头有一张AKD市的地图.这张地图是边长为m*n的矩形,被划分为m*n个1*1的小正方形.对于每个小正方形,地图上已经标注了它的海拔高度以及它是否是A

Linux编程之ICMP洪水攻击

我的上一篇文章<Linux编程之PING的实现>里使用ICMP协议实现了PING的程序,ICMP除了实现这么一个PING程序,还有哪些不为人知或者好玩的用途?这里我将介绍ICMP另一个很有名的黑科技:ICMP洪水攻击. ICMP洪水攻击属于大名鼎鼎的DOS(Denial of Service)攻击的一种,一种是黑客们喜欢的攻击手段,这里本着加深自己对ICMP的理解的目的,也试着基于ICMP写一段ICMP的洪水攻击小程序. 洪水攻击(FLOOD ATTACK)指的是利用计算机网络技术向目的主机发

IP报文解析及基于IP 数据包的洪水攻击

版本(4bit) 报头长度(4bit) 优先级和服务类型(8bit) 总长度(16bit) 标识(16bit) 标志(3bit) 分段偏移(13bit) 存活期(8bit) 协议(8bit) 报头校验和(16bit) 源IP地址(32bit) 目的IP地址(32bit) 选项(0或32bit,若有的话) 数据(可变) 版本 IP版本号.报头长度 32位字的报头长度(HLEN).优先级和服务类型 服务类型描述数据报将如何被处理.前3位表示优先级位.总长度 包括报头和数据的数据包长度.标识 唯一的I

洪水 Pow

Description AKD市处在一个四面环山的谷地里.最近一场大暴雨引发了洪水,AKD市全被水淹没了.Blue Mary,AKD市的市长,召集了他的所有顾问(包括你)参加一个紧急会议.经过细致的商议之后,会议决定,调集若干巨型抽水机,将它们放在某些被水淹的区域,而后抽干洪水. 你手头有一张AKD市的地图.这张地图是边长为m*n的矩形,被划分为m*n个1*1的小正方形.对于每个小正方形,地图上已经标注了它的海拔高度以及它是否是AKD市的一个组成部分.地图上的所有部分都被水淹没了.并且,由于这张

洪水攻击怎么办?

洪水攻击是网络攻击里比较常见的一种,一般体现就是机器慢(CPU居高不下),ssh等网络服务登陆缓慢甚至会出现登陆不上的情况,甚至在# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' 的命令里,发现SYN_RECV 的数量要远远大于ESTABLISHED的数量(几乎是5~8倍以上),然后查看系统的日志或者使用#dmesg的时候,就会出现如下的语句: possible SYN flooding on port