地址:http://poj.org/problem?id=1434

题目:Fill the Cisterns!

Fill the Cisterns!
Time Limit: 5000MS   Memory Limit: 10000K
Total Submissions: 4131   Accepted: 1360

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

 
思路:
  二分
 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath> using namespace std; #define MP make_pair
#define PB push_back
#define lc (o<<1)
#define rc (o<<1|1)
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=5e4+;
const int mod=1e9+; struct node
{
double b,h,s;
bool operator < (const node &ta) const
{
return b<ta.b;
}
}cis[K];
int n;
double v;
int sgn(double ta,double tb)
{
if(fabs(ta-tb)<eps) return ;
return ta<tb?-:;
}
bool check(double x)
{
double ret=;
for(int i=;i<=n;i++)
{
if(sgn(cis[i].b,x)>) break;
ret+=cis[i].s*min(cis[i].h,x-cis[i].b);
}
return sgn(ret,v)>=;
}
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
double sum=,l=1e9,r=-1e9;
for(int i=;i<=n;i++)
{
double b,h,w,d;
scanf("%lf%lf%lf%lf",&b,&h,&w,&d);
cis[i]=(node){b,h,w*d};
sum+=h*w*d;
l=min(l,b),r=max(r,b+h);
}
sort(cis+,cis++n);
scanf("%lf",&v);
if(sgn(v,sum)>)
{
printf("OVERFLOW\n");
continue;
}
while(r-l>0.001)
{
double mid=(l+r)/;
if(check(mid))
r=mid;
else
l=mid;
}
printf("%.2f\n",l);
}
return ;
}

poj1434 Fill the Cisterns!的更多相关文章

  1. POJ 1434 Fill the Cisterns! (模拟 or 二分)

    Fill the Cisterns! 题目链接: http://acm.hust.edu.cn/vjudge/contest/129783#problem/F Description During t ...

  2. [转] POJ计算几何

    转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板 ...

  3. 狗狗40题~ (Volume C)

    A - Triangles 记忆化搜索呗.搜索以某三角形为顶的最大面积,注意边界情况. #include <stdio.h> #include <cstring> #inclu ...

  4. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  5. iOS 2D绘图 (Quartz2D)之路径(stroke,fill,clip,subpath,blend)

    像往常一样 这个系列的博客是跟着大神的脚步来的.按照往例 在此贴出原博客的出处: http://blog.csdn.net/hello_hwc?viewmode=list我对大神的崇拜之情 如滔滔江水 ...

  6. dev_set_draw的fill和margin模式

    注意:分别观察两张填充模式,一种是内部填充,一种是边缘填充.还有一种缺省的填充. Name dev_set_draw — Define the region fill mode. Signature ...

  7. scala 学习之: list.fill 用法

    题目描述: Decode a run-length encoded list. Given a run-length code list generated as specified in probl ...

  8. 急!JDBC问题,发生通信错误。错误位置:Reply.fill()。消息:数据不足。 ERRORCODE=-4499, SQLSTATE=08001

    代码如下:Class.forName("com.ibm.db2.jcc.DB2Driver");Connection conn = DriverManager.getConnect ...

  9. [javascript svg fill stroke stroke-width points polygon属性讲解] svg fill stroke stroke-width points polygon绘制多边形属性并且演示polyline和polygon区别讲解

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

随机推荐

  1. mac 安装mysql 修改密码

    我草!!! 上网查资料,安装mysql,一大推废话,简直就是他妈的瞎扯淡,真是能他妈的瞎编,草! 为了不让后面的同学看到那些狗屁不通的资料,我把自己安装mysql的步骤,以及修改mysql密码的方法梳 ...

  2. js里面声明变量时候的注意事项

    变量名可以是中文,只能有下划线,$,数字和字母组成,开头只能以下划线(不建议使用)和字母开头.

  3. php学习一:语法规则

    1.书写规则 在html中嵌入php的时候,需要有结束语,即<?php ...?>,在靠近结束符号的最后一个语句可以不用写分号: 但是在单独的php中,最后可以不用以?>来结尾; 2 ...

  4. iOS - UITableView判断reloadData加载数据已经结束

    问题: stackoverflow上有人提问这样的问题 http://stackoverflow.com/questions/16071503/how-to-tell-when-uitableview ...

  5. 【WebService】快速构建WebService示例

    package com.slp.webservice; import javax.jws.WebService; /** * Created by sanglp on 2017/2/25. * 接口 ...

  6. 原创Java多线程详解(一)

    只看书不实践是不行的.来实践一下~~~~~~(引用请指明来源) 先看看百科对多线程的介绍 多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的 ...

  7. <a>标签实现链接和锚点的区别

    如果是实现链接,a标签中必须有href属性,并且属性值是合法的url 如果实现锚点,a标签中必须有name属性,当点击该标签时,会跳转到id同该标签的name值相同的元素处.

  8. 图片的ScaleType详解 ImageView的属性android:scaleType,

    imageView.setScaleType(ImageView.ScaleType.FIT_XY ); 这里我们重点理解ImageView的属性android:scaleType,即ImageVie ...

  9. python range函数与numpy arange函数

    1.range()返回的是range object,而np.arange()返回的是numpy.ndarray() range尽可用于迭代,而np.arange作用远不止于此,它是一个序列,可被当做向 ...

  10. postgresql----INSERT

    INSERT即向表中写入数据,每条INSERT语句可以写入一条数据,也可以写入多条数据.另外还可以将其他的查询结果集用在INSERT中,将查询结果写入表中. 测试表 test)); CREATE TA ...