链接

题目说给你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. java JPEGImageEncoder;图像处理

    在Eclipse中处理图片,需要引入两个包: import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JP ...

  2. Serializable接口使用纪实

    这两天依领导要求使用sonar工具测试了一下项目代码,其中有一个问题是 而这个类的结构大概是这样的: public class Demo<T> implements Serializabl ...

  3. 链表——PowerShell版

    链表是由一系列节点串连起来组成的,每一个节点包括数值部分和指针部分,上一节点的指针部分指向下一节点的数值部分所在的位置. 在C语言中我们有两种方式来定义链表—— 1.定义结构体:来表示链表中的节点,节 ...

  4. 使用main方法调用http请求本地服务器的某个servlet报错问题

    java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8081/test/myS ...

  5. JAVA获取密钥公钥的keytool的使用

    一.keytool的概念 keytool 是个密钥和证书管理工具.它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数字签名)自我认证(用户向别的用户/服务认证自己)或数据完整性以及认证服务.在 ...

  6. key可以重复的Map集合:IdentityHashMap

    所有Map操作中key的值是不能重复的,例如,HashMap操作时key是不能重复的,如果重复则肯定会覆盖之前的内容,如下代码所示. 范例:Map中的key不允许重复,重复就是覆盖 package o ...

  7. 2013年江西理工大学C语言程序设计竞赛(初级组)

    ACM ICPC WORLD FINAL 解法:排序大家都知道,去重的话,初学者用数组就好了 #include<algorithm> #include<iostream> us ...

  8. OS开发(Objective-C)常用库索引

    code4app.com 这网站不错,收集各种 iOS App 开发可以用到的代码示例 cocoacontrols.com/ 英文版本的lib收集 objclibs.com/ 精品lib的收集网站 h ...

  9. hao dongxi

    asp.net页面间传值方式后台 asp.net页面间传值的几种方法 利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. json的使用 前后台统一以对象的方式编程 ASP. ...

  10. Apache Commons CLI 开发命令行工具示例

    概念说明Apache Commons CLI 简介 虽然各种人机交互技术飞速发展,但最传统的命令行模式依然被广泛应用于各个领域:从编译代码到系统管理,命令行因其简洁高效而备受宠爱.各种工具和系统都 提 ...