博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj1434
阅读量:7238 次
发布时间:2019-06-29

本文共 1673 字,大约阅读时间需要 5 分钟。

二分

简单题

ContractedBlock.gif
ExpandedBlockStart.gif
View Code
#include 
#include
#include
#include
using namespace std; #define maxn 50005 #define eps 10e-9 struct Cistern {
double b, w, h, d; }cistern[maxn]; double total; int n; double v; double maxh; int dblcmp(double a, double b) {
if (a + eps < b) return -1; if (a - eps > b) return 1; return 0; } void input() {
total = 0; maxh = 0; scanf("%d", &n); for (int i = 0; i < n; i++) {
scanf("%lf%lf%lf%lf", &cistern[i].b, &cistern[i].h, &cistern[i].w, &cistern[i].d); total += cistern[i].h * cistern[i].w * cistern[i].d; maxh = max(maxh, cistern[i].h + cistern[i].b); } scanf("%lf", &v); } bool high(double h) {
total = 0; for (int i = 0; i < n; i++) if (dblcmp(cistern[i].b, h) <= 0 && dblcmp(cistern[i].b + cistern[i].h, h) >= 0) total += (h - cistern[i].b) * cistern[i].w * cistern[i].d; else if (dblcmp(cistern[i].b + cistern[i].h, h) <= 0) total += cistern[i].h * cistern[i].w * cistern[i].d; return dblcmp(total, v) >= 0; } double binarysearch() {
double l = 0; double r = maxh; while (dblcmp(l, r) != 0) {
double mid = (l + r) / 2; if (high(mid)) r = mid; else l = mid; } return l; } int main() {
//freopen("t.txt", "r", stdin); int t; scanf("%d", &t); while (t--) {
input(); if (total < v) {
printf("OVERFLOW\n"); continue; } printf("%.2f\n", binarysearch()); } return 0; }

转载于:https://www.cnblogs.com/rainydays/archive/2011/07/19/2110718.html

你可能感兴趣的文章
监控摄像机选型攻略之技术类型选用
查看>>
JAVA笔记——序列化
查看>>
《数据科学:R语言实现》——3.1 引言
查看>>
协作软件的前景、进展以及阵痛
查看>>
PyTorch 和 TensorFlow 哪个更好?看一线开发者怎么说
查看>>
怎么善于发现seo网站优化的问题?
查看>>
《Metasploit渗透测试手册》—第8章8.1节介绍
查看>>
《UG NX8.0中文版完全自学手册》一1.4 工具栏的定制
查看>>
合三为一,Linux 基金会欲打造顶级开源峰会
查看>>
《计算机系统:系统架构与操作系统的高度集成》——2.8 编译函数调用
查看>>
不要成为工具的奴隶
查看>>
IO多路复用之select/poll/epoll总结
查看>>
菜鸟Vue学习笔记(一)
查看>>
好程序员web前端分享CSS3 边框
查看>>
干货|数据区块链在钢铁行业的应用(分享实录)
查看>>
Java NIO(五)Scatter Gather
查看>>
Android 8.1平台SystemUI虚拟导航键加载流程解析
查看>>
ViewPager2结合TabLayout
查看>>
java 异常
查看>>
动手实现一致性哈希算法,并搭建环境测试其负载均衡特性.
查看>>