链接

题目说给你n个水箱,初始是没有水的,每个的高低位置可能不同,给了你初始的水箱底部所处的水平线位置,问给你V体积水时,水的水平线位置。

直接二分位置p,对于每一个底部低于水平线位置的水箱,里面的水的体积 = min(h,p-b)*w*d;

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 50005
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct node
{
int b,h,w,d;
}p[N];
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double cal(double mid,int n)
{
int i;
double s = ;
for(i = ; i <=n;i++)
{
if(p[i].b>mid) continue;
s+=min(mid-p[i].b,p[i].h*1.0)*p[i].w*p[i].d;
}
return s;
}
int main()
{
int v,n,i,t;
cin>>t;
while(t--)
{
scanf("%d",&n);
double s = ;
for(i = ; i <=n; i++)
{
scanf("%d%d%d%d",&p[i].b,&p[i].h,&p[i].w,&p[i].d);
s+=p[i].h*p[i].w*p[i].d;
}
scanf("%d",&v);
if(dcmp(v-s)>)
{
puts("OVERFLOW");
continue;
}
double rig = 2000000.0,lef = ,mid;
while(rig-lef>eps)
{
mid = (rig+lef)/2.0;
if(dcmp(cal(mid,n)-v)>=)
rig = mid;
else lef = mid;
}
printf("%.2f\n",rig);
}
return ;
}

poj1434Fill the Cisterns!(二分)的更多相关文章

  1. 狗狗40题~ (Volume C)

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

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

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

  3. poj1434 Fill the Cisterns!

    地址:http://poj.org/problem?id=1434 题目:Fill the Cisterns! Fill the Cisterns! Time Limit: 5000MS   Memo ...

  4. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  5. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  6. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  7. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

  8. [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  9. [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值

    Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...

随机推荐

  1. Unix/Linux编程实践教程(二:socket、多线程、进程间通信)

    同一接口不同的数据源: 协同进程: fdopen以文件描述符为参数: fopen和popen: 为了实现popen,必须在子进程中调用sh,因为只有shell本身即/bin/sh可以运行任意shell ...

  2. js声明

    var a = 2; //我们习惯把这条语句当做一条声明 但是js引擎把它当做两条声明. var a; //在编译时执行  同时var a;存在提升 a = 2;//在运行是执行  赋值lhs不会提升 ...

  3. 约瑟夫问题 java

    约瑟夫环:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到m的那个人出列;他的下一个人又从1开始报数,数到m的那个人又出列;依此规律重复下去,直到圆桌周围 ...

  4. Struts输出流向jsp页面写入图片乱码

    通过Struts2输出字节流将图片写到jsp页面上,之前用jquery的div对象的html()方法接收一直显示乱码,查了很多网页都找不到解决办法,不是说contentype="multip ...

  5. Djnago的一些零碎知识点

    1.TEMPLATE_DIRS relative to the project folder http://stackoverflow.com/questions/9856683/using-pyth ...

  6. android的基础入门

        一.   A通信技术   1. 1G  仅限语音的蜂窝式通话标准 2. 2G  (时分多路复用)数字语音传输技术和增加接收数据的功能 3. 3G  传输声音和数据的速度有很大的 提升 4. 4 ...

  7. 【20160924】GOCVHelper MFC增强算法(1)

        //递归读取目录下全部文件(flag为r的时候递归)     void getFiles(string path, vector<string>& files,string ...

  8. HTTP 错误 404.2 - Not Found

    前几天刚安装Windows Server 2008 r2 sp1 遇到问题之后,昨天我又遇到一个问题(但我不害怕有问题),提示: HTTP 错误 404.2 - Not Found由于 Web 服务器 ...

  9. CSU 1325: A very hard problem 中南月赛的一道题。

    1325: A very hard problem Time Limit: 3 Sec  Memory Limit: 160 MBSubmit: 203  Solved: 53[Submit][Sta ...

  10. 关于MYSQL group by 分组按时间取最大值的实现方法!

    类如 有一个帖子的回复表,posts( id , tid , subject , message , dateline ) , id 为 自动增长字段, tid为该回复的主题帖子的id(外键关联), ...