poj1434 Fill the Cisterns!
地址:http://poj.org/problem?id=1434
Time Limit: 5000MS | Memory Limit: 10000K | |
Total Submissions: 4131 | Accepted: 1360 |
Description
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 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
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!的更多相关文章
- POJ 1434 Fill the Cisterns! (模拟 or 二分)
Fill the Cisterns! 题目链接: http://acm.hust.edu.cn/vjudge/contest/129783#problem/F Description During t ...
- [转] POJ计算几何
转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板 ...
- 狗狗40题~ (Volume C)
A - Triangles 记忆化搜索呗.搜索以某三角形为顶的最大面积,注意边界情况. #include <stdio.h> #include <cstring> #inclu ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- iOS 2D绘图 (Quartz2D)之路径(stroke,fill,clip,subpath,blend)
像往常一样 这个系列的博客是跟着大神的脚步来的.按照往例 在此贴出原博客的出处: http://blog.csdn.net/hello_hwc?viewmode=list我对大神的崇拜之情 如滔滔江水 ...
- dev_set_draw的fill和margin模式
注意:分别观察两张填充模式,一种是内部填充,一种是边缘填充.还有一种缺省的填充. Name dev_set_draw — Define the region fill mode. Signature ...
- scala 学习之: list.fill 用法
题目描述: Decode a run-length encoded list. Given a run-length code list generated as specified in probl ...
- 急!JDBC问题,发生通信错误。错误位置:Reply.fill()。消息:数据不足。 ERRORCODE=-4499, SQLSTATE=08001
代码如下:Class.forName("com.ibm.db2.jcc.DB2Driver");Connection conn = DriverManager.getConnect ...
- [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 ...
随机推荐
- hex()
hex() 用于将十进制数字转换成十六进制 In [1]: hex(10) Out[1]: '0xa' In [2]: hex(11) Out[2]: '0xb'
- Serlvet学习笔记之二—不同页面共享数据
一共有四种方法实现共享页面共享数据 1.cookie 2.sendRedirect 3.session 4.隐藏表单提交(form) 5.ServletContex 1.cookie:服务器在客户端保 ...
- (使用lua++)Lua脚本和C++交互(三)
前两篇文章中介绍了C++调用lua.lua栈操作的一些相关知识. 下面说一下Lua的工具.我们下一步要用到其中的一个帮助我们的开发,其实,Lua里面有很多简化开发的工具,你可以去www.sourcef ...
- c++中new/operator new/placement new
1. new/delete c++中的new(和对应的delete)是对堆内存进行申请和释放,且两个都不能被重载. 2. operator new/operator delete c++中如果想要实现 ...
- java 集合之HashMap
原文出处http://zhangshixi.iteye.com/blog/672697 1. HashMap概述: HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操 ...
- JDBC处理文本和二进制文件
JDBC支持文本(CLOB)和二进制(BLOB)文件的处理,比如要往数据库里存取文章或者图片.这都是用流的思想来解决的. 来两个Demo看看JDBC是怎么操作文本和二进制文件的. CLOB: pack ...
- whistle--全新的跨平台web调试工具
版权声明:本文由吴文斌原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/151 来源:腾云阁 https://www.qclo ...
- 【BZOJ2588】Spoj 10628. Count on a tree 主席树+LCA
[BZOJ2588]Spoj 10628. Count on a tree Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lasta ...
- java如何随机生成定长的字符串
小数,字符串.时间等示例代码 String base = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 public c ...
- ExtJS学习
ExtJS是一门比较纠结的框架,自己不太熟,因为现在在做一些老项目,所以没办法要学点.记录下.其实Ext也不是很难,主要是多查查API,了解其基本的用法,然后慢慢去学习,学成之后做管理系统还是很有优势 ...