poj 1434 Fill the Cisterns!(扫描线)
来源:互联网 发布:淘宝买亚马逊礼品卡 编辑:程序博客网 时间:2024/05/21 20:23
Fill the Cisterns!
Time Limit: 5000MS Memory Limit: 10000KTotal Submissions: 2513 Accepted: 900
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.
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.
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.
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
320 1 1 12 1 1 11411 7 5 115 6 2 25 8 5 119 4 8 1132411 7 5 115 6 2 25 8 5 119 4 8 178
Sample Output
1.00OVERFLOW17.00
Source
Central Europe 2001
题目:http://poj.org/problem?id=1434
题意:给你n个相连的长方体容器,每个容器的高度不一,现在在容器里装体积为V的水,问是否能装下,能装下的话,水的最大高度是多少
分析:水往地处流,所有我们当然是从最底层开始装水,将所有高度离散化,这样对于许多长方体块,算出单位高度的装水量,也就是高度对应的面积,从下往上统计就行了
还有另一种做法就是二分高度,判断是否能装下,这里就不写了
代码:
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int mm=111111;struct data{ int h,x;}g[mm];int s[mm];int i,n,m,b,h,w,d,t;double sum,ans,v;bool cmp(data a,data b){ return a.h<b.h;}int main(){ scanf("%d",&t); while(t--) { scanf("%d",&n); for(sum=m=0,i=1;i<=n;++i) { scanf("%d%d%d%d",&b,&h,&w,&d); s[i]=w*d; g[m].h=b,g[m++].x=i; g[m].h=b+h,g[m++].x=-i; sum+=1.0*h*w*d; } scanf("%lf",&v); if(v>sum)puts("OVERFLOW"); else { sort(g,g+m,cmp); ans=g[0].h; for(sum=i=0;v>0&&i<m;++i) { if(i>0&&g[i].h>g[i-1].h) { v-=sum*(g[i].h-g[i-1].h); ans+=(g[i].h-g[i-1].h); if(v<0)ans+=v/sum; } if(g[i].x<0)sum-=s[-g[i].x]; else sum+=s[g[i].x]; } printf("%.2lf\n",ans); } } return 0;}
- poj 1434 Fill the Cisterns!(扫描线)
- poj 1434 Fill the Cisterns! (二分)
- POJ 1434 Fill the Cisterns!(二分)
- POJ 1434 Fill the Cisterns!(二分)
- POJ 1434 Fill the Cisterns
- POJ 1434 Fill the Cisterns!
- POJ 1434 Fill the Cisterns!
- POJ 1434 Fill the Cisterns!(二分)
- POJ 1434 Fill the Cisterns!(二分)
- POJ 1434 Fill the Cisterns! 笔记
- poj 1434 --Fill the Cisterns!(计算几何,二分)
- POJ 1434 Fill the Cisterns!(计算几何,二分)
- POJ1434-Fill the Cisterns!
- POJ1434 Fill the Cisterns! 二分法
- POJ_1434_Fill the Cisterns!
- poj1434Fill the Cisterns!【二分+计算几何】
- 填充正方形(Fill the Square)
- uva 11520 Fill the Square(DFS)
- 读取Xml文件,创建DataTable,递归循环读取Xml数据添加到DataTable,绑定数据到GridView
- struts2 jquery ajax 返回jason类型遇到问题总结
- 对oracle索引的认识及相关操作
- 递归循环读取Xml
- chapter6:python 抽象
- poj 1434 Fill the Cisterns!(扫描线)
- 泛型
- PHP调试工具Xdebug安装
- PyQt布局
- 解析自定义头像、链接、处理微博上类似 “@” 和 “#” 的特殊转义字符并在UIWebView显示的例子
- C# 去除字符串中的非法字符
- 浮华落寂
- __declspec(dllimport) .
- Android开发:实现带图片和checkbox的listview