1999 ICPC WF H Flooded! 【思维】【细节】
来源:互联网 发布:php数组是什么数据结构 编辑:程序博客网 时间:2024/05/21 10:00
题目链接:
UVA-815
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 lowlying 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(1≤m,n<30)的网格,每个格子是边长10米的正方形,网格四周是无限大的墙壁。输入每个格子的海拔高度,以及网格内雨水的总体积,输出水位的海拔高度以及有多少百分比的区域有水(即高度严格小于水平面)。
解题思路:
因为雨水始终是从高处往低处流淌的,所以水位的海拔高度只与每个格子的高度有关,而与格子的布局无关。为了方便模拟雨水的上升过程,我们将所有格子按照从低到高的顺序排在一条直线上,依次加水,直到水位高于下一格子,再以下一格子为基准加水……这样最终会出现两种情况:第一,水位高于最高的格子;第二,水位位于其中俩个格子之间。然后分类讨论就好了。出现后者的情况时我用二分求解的最终结果。
Mycode:
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int MAX = 1005;const int MOD = 1e9+7;const int INF = 0x3f3f3f3f;const double eps = 1e-8;double a[MAX];int main(){ int n, m; int cas = 0, tot, num; double wat, res, tem, ans; while(cin >> n >> m && m) { tot = 0; n *= m; for(int i = 0; i < n; ++i) cin >> a[i]; sort(a, a+n); cin >> wat; wat /= 100; num = -1; tem = 0; for(int i = 1; i < n; ++i) { tem += (a[i] - a[i-1])*i; if(tem >= wat) { num = i; break; } } if(num == -1) //全部淹没 { ans = a[n-1] + (wat - tem)/n; tot = n; } else { tem -= (a[num]-a[num-1])*num; double l = a[num-1], r = a[num]; double hh = l; while(r-l > eps) { double mid = (r+l)/2; if(tem + (mid-hh)*num > wat) r = mid; else l = mid; } ans = l; for(int i = 0; i < n; ++i) { if(a[i] < ans) tot++; } } res = 100.0 * tot / n; printf("Region %d\n",++cas); printf("Water level is %.2f meters.\n",ans); printf("%.2f percent of the region is under water.\n",res); puts(""); } return 0;}
- 1999 ICPC WF H Flooded! 【思维】【细节】
- 1999 ICPC WF C Morse Mismatches 【模拟】
- Flooded!
- 1990 ICPC WF B Squares【暴力】
- The 2016 ACM-ICPC Asia China-Final Contest H题 数学 + 思维
- UVA-815 flooded!(白书说能锻炼思维的题)
- 1990 ICPC WF C Repeating Decimals 【数组和字符串】【模拟】
- WF
- wf
- ACM-ICPC-ChinaFinal-H题
- 2016ICPC大连站 H
- 815 - Flooded!
- poj1877 Flooded!
- 815 - Flooded!
- UVA815 - Flooded!
- UVA_815: Flooded!
- UVA815--Flooded
- h.264的技术细节
- leetcode520. Detect Capital
- 数据持久化
- Java学习笔记---增强for循环
- 蓝桥-ALGO-33-数列
- Oracle中的查询转换简介(上)
- 1999 ICPC WF H Flooded! 【思维】【细节】
- PDFBinder1.2汉化版,tek2y原创汉化!
- 文章标题
- 《Javascript语言精粹》
- 100 数组和指针绝不等价,数组是另外一种类型
- 生成指定范围内无重复的随机乱序数组(JAVA实现/时间复杂度为O(n))
- 7. Reverse Integer
- 利用Spring AOP自定义注解解决日志和签名校验 详解
- Android加载框