Fill the Cisterns!
题目链接:
http://acm.hust.edu.cn/vjudge/contest/129783#problem/F
Description
During the next century certain regions on earth will experience severe water shortages. The old town of Uqbar has already started to prepare itself for the worst. Recently they created a network of pipes connecting the cisterns that distribute water in each neighbourhood, making it easier to fill them at once from a single source of water. But in case of water shortage the cisterns above a certain level will be empty since the water will to the cisterns below. You have been asked to write a program to compute the level to which cisterns will be lled with a certain volume of water, given the dimensions and position of each cistern. To simplify we will neglect the volume of water in the pipes. Task Write a program which for each data set: reads the description of cisterns and the volume of water, computes the level to which the cisterns will be filled with the given amount of water, writes the result.Input
The first line of the input contains the number of data sets k, 1 <= k <= 30. The data sets follow. The first line of each data set contains one integer n, the number of cisterns, 1 <= n <= 50 000. Each of the following n lines consists of 4 nonnegative integers, separated by single spaces: b, h, w, d - the base level of the cistern, its height, width and depth in meters, respectively. The integers satisfy 0 <= b <= 10^6 and 1 <= h * w * d <= 40 000. The last line of the data set contains an integer V - the volume of water in cubic meters to be injected into the network. Integer V satisfies 1 <= V <= 2 * 10^9.Output
The output should consist of exactly d lines, one line for each data set. Line i, 1 <= i <= d, should contain the level that the water will reach, in meters, rounded up to two fractional digits, or the word 'OVERFLOW', if the volume of water exceeds the total capacity of the cisterns.Sample Input
``` 3 2 0 1 1 1 2 1 1 1 1 4 11 7 5 1 15 6 2 2 5 8 5 1 19 4 8 1 132 4 11 7 5 1 15 6 2 2 5 8 5 1 19 4 8 1 78 ```Sample Output
``` 1.00 OVERFLOW 17.00 ```Source
2016-HUST-线下组队赛-3##题意: 给出n个长方体水箱,从下往上依次注入V升水. 求最后结果的高度.
##题解: 对长方体的上下底面排序后直接模拟即可,维护当前高度时长方体的截面面积之和. 每次枚举到下底时把面积加入,枚举到下底时减去面积. 当枚举到某个上底时,水不够注满到这个高度,那么用剩余体积除以当前截面,就是剩下的高度. 还有种做法是二分最终高度,并遍历所有长方体计算是否能够用.
这道水题成为了今天的败笔. 2个多小时才过. 一开始就想的是二分,然后我特意处理都乘了个100来避免浮点数. 结果WA. 应该是因为可能不能恰好用完导致的. 然后改成double的还是WA. 后来重写了一份模拟,还是WA. 错点在于,一开始把rounded up错误理解成为向上取整,结果每次输出我都加了个0.005导致GG. 模拟过了之后以为二分的精度不够,这题不能用二分. 回来补题才发现输出一定只能用 %f , 不能用 %lf. (否者WA,至于精度,各种姿势处理都能过).
double输出再用%lf就吃键盘!!!!!
##代码: ####模拟: ``` cpp #include