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 ...
随机推荐
- SPI接口功能描述
- docker nginx mysql
docker run -p 9000:9000 --name myphp -v /docker/www/:/var/www/html/ -v /docker/php/php.ini:/usr/loca ...
- linux配置了dns后导致mysql远程连接慢问题
有时候dns配置错误或者其它原因会导致mysql远程连接缓慢,此时只需要关闭mysqlDNS反向解析即可解决此问题. 打开my.cnf配置,将[mysqld]下的#skip-name-resolve前 ...
- ASP.NET 4.0尚未在Web服务器注册 解决
http://www.cnblogs.com/lvxiouzi/p/3511446.html 安装asp.net 4.0.30319.0版本 命令: %windir%\Microsoft.NET\Fr ...
- c++11——右值引用
1. 左值和右值 左值是表达式结束之后仍然存在的持久化对象,而右值是指表达式结束时就不再存在的临时对象. c++11中,右值分为两种类型:将亡值(xvalue, expiring value) ...
- java基础---->java多线程之Join(二)
如果主线程想等待子线程执行完成之后再结束,就可以使用join方法了.它的使用是等待线程对象销毁.今天我们就通过实例来学习一下多线程中join方法的使用.草在结它的种子,风在摇它的叶子.我们站着,不说话 ...
- The 70th problem,UVa10396 Vampire Numbers
今天看Thinking in Java看到一个吸血鬼数的问题,于是查找UVa里也有类似的问题就动手写了先是用Java写的,不过WA了两次,然后没有发现错误,又用c++写的还是不行.最后发现要排序去重. ...
- ntpdate自动对准时间的脚本
author:headsen chen date: 2018-10-09 19:50:15 #!/bin/bash yum -y install ntpdate /usr/sbin/ntpdate ...
- Navicat 创建 Mysql 函数
1.点击新建函数 2.写函数,保存为v1 3.调用 SELECT id,v1(id) from 表
- 【BZOJ2118】墨墨的等式 最短路
[BZOJ2118]墨墨的等式 Description 墨墨突然对等式很感兴趣,他正在研究a1x1+a2y2+…+anxn=B存在非负整数解的条件,他要求你编写一个程序,给定N.{an}.以及B的取值 ...