poj1434Fill the Cisterns!【二分+计算几何】
来源:互联网 发布:淘宝客服绩效管理 编辑:程序博客网 时间:2024/06/04 08:03
Language:
Fill the Cisterns!
Time Limit: 5000MS Memory Limit: 10000KTotal Submissions: 3648 Accepted: 1224
Description
During the next century certain regions on earth will experience severe water shortages. The old town of Uqbar has already started to prepare itself for the worst. Recently they created a network of pipes connecting the cisterns that distribute water in each neighbourhood, making it easier to fill them at once from a single source of water. But in case of water shortage the cisterns above a certain level will be empty since the water will to the cisterns below.
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.
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 the input contains the number of data sets k, 1 <= k <= 30. The data sets follow.
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.
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
The output should consist of exactly d lines, one line for each data set.
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.
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
320 1 1 12 1 1 11411 7 5 115 6 2 25 8 5 119 4 8 1132411 7 5 115 6 2 25 8 5 119 4 8 178
Sample Output
1.00OVERFLOW17.00
题意:求将体积为V的水倒入上图所示结构水位能到达的最大高度
解题思路二分
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#define eps 1e-8#define inf 0x3f3f3f3fusing namespace std;struct Node{double l,h,w,d;}A[50010];double MIN(double a,double b){return a<b?a:b;}double MAX(double a,double b){return a>b?a:b;}int main(){int t,i,j,n;double volum,left,right,v=0;scanf("%d",&t);while(t--){scanf("%d",&n);left=inf;right=0;v=0;for(i=0;i<n;++i){scanf("%lf%lf%lf%lf",&A[i].l,&A[i].h,&A[i].w,&A[i].d);v+=A[i].h*A[i].w*A[i].d;left=MIN(A[i].l,left);right=MAX(A[i].h+A[i].l,right);}scanf("%lf",&volum);if(volum-v>eps){printf("OVERFLOW\n");continue;}while(right-left>eps){double mid=(left+right)/2.0;v=0;for(i=0;i<n;++i){if(mid-A[i].l>=0){if(mid-(A[i].h+A[i].l)>=0){v+=A[i].d*A[i].h*A[i].w;}else{v+=A[i].d*A[i].w*(mid-A[i].l);}}}if(v>=volum){right=mid;}else{left=mid;}} printf("%.2lf\n",right);}return 0;}
0 0
- poj1434Fill the Cisterns!【二分+计算几何】
- poj 1434 --Fill the Cisterns!(计算几何,二分)
- POJ 1434 Fill the Cisterns!(计算几何,二分)
- poj 1434 Fill the Cisterns! (二分)
- POJ 1434 Fill the Cisterns!(二分)
- POJ 1434 Fill the Cisterns!(二分)
- POJ 1434 Fill the Cisterns!(二分)
- POJ 1434 Fill the Cisterns!(二分)
- 计算几何 [二分答案]
- POJ1434-Fill the Cisterns!
- POJ_1434_Fill the Cisterns!
- HDU 4033 二分+计算几何
- poj2398+poj2318(计算几何+二分)
- POJ 2318 计算几何+二分
- poj2318 toy 计算几何+二分
- hdoj4643GSM【计算几何+二分思想】
- poj2857Expanding Rods【二分+计算几何】
- 计算几何-二分求幂
- IOS沙盒机制的理解
- c++ primer第五版(中文)习题答案 第十章第二节第三小节-重排容器元素的算法
- ssh架构不能自动生成建表语句
- Robot framework中元素的定位
- 三层架构
- poj1434Fill the Cisterns!【二分+计算几何】
- iOS 手势识别与操作 UIGestureRecognizer
- c/c++ sort函数的用法
- 无法将参数 1 从“char ”转换为“LPWSTR”
- 使用MSScriptControl 在 C# 中读取json数据
- 个人学习过程中遇到的疑难杂症(笔记,持续更新中……)
- IP地址、子网掩码、网络号、主机号、网络地址、主机地址
- 搭建Spring、Spring MVC、Mybatis和Freemarker
- android ViewGroup的事件分发机制