poj 1434 Fill the Cisterns! (二分)

原创 2013年12月01日 20:25:26
Fill the Cisterns!
Time Limit: 5000MS   Memory Limit: 10000K
Total Submissions: 3088   Accepted: 1051

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. 

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. 

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. 

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


题意:求给定的水,可以把连通器装到多少高度,若有水剩余则输出OVERFLOW
题解:二分高度,然后枚举计算其所需的水量就行了,注意控制好精度(一开始我竟然将double当int传。。弱啊)

#include<stdio.h>
#define eps 1e-4
struct cistern{
    double b,h,w,d;
}cc[50008];
int n;
double MIN(double x,double y){ return x<y?x:y; }
double cal(double mid)
{
    int i;
    double res=0;

    for(i=0;i<n;i++)
    {
        if(mid>cc[i].b)
        {
            res+=MIN(cc[i].h,mid-cc[i].b)*cc[i].w*cc[i].d;
        }
    }

    return res;
}
double solve(double all)
{
    double left=0,right=1000000000,mid;

    while(left+eps<right)
    {
        mid=(left+right)/2.0;
        if(cal(mid)<all) left=mid;
        else right=mid;
    }

    return left;
}
int main()
{
    int t,i;
    double all,overflow;

    //freopen("t.txt","r",stdin);
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(overflow=i=0;i<n;i++)
        {
            scanf("%lf%lf%lf%lf",&cc[i].b,&cc[i].h,&cc[i].w,&cc[i].d);
            overflow+=cc[i].h*cc[i].w*cc[i].d;
        }
        scanf("%lf",&all);
        if(overflow<all) printf("OVERFLOW\n");
        else printf("%.2lf\n",solve(all)+eps);
    }
}


相关文章推荐

poj 1434 --Fill the Cisterns!(计算几何,二分)

http://poj.org/problem?id=1434Fill the Cisterns!Time Limit: 5000MS Memory Limit: 10000KTotal Submiss...

POJ 1434 Fill the Cisterns!(计算几何,二分)

一些不同高度的水箱组成连通器,求装下V体积液体时液面的高度 将水箱按底部高排序。然后二分液面高度就可以了 //Memory: 1744 KB //Time: 1391 MS #includ...

poj1434Fill the Cisterns!【二分+计算几何】

Language: Default Fill the Cisterns! Time Limit: 5000MS   Memory Limit: 10000K T...

poj 1434 Fill the Cisterns!(扫描线)

Fill the Cisterns! Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 2513...
  • fp_hzq
  • fp_hzq
  • 2012年09月14日 18:03
  • 564

POJ_1434_Fill the Cisterns!

Fill the Cisterns! Time Limit: 5000M Memory Limit: 10000K ...
  • Mrx_Nh
  • Mrx_Nh
  • 2016年10月01日 03:08
  • 99

POJ 1434 Fill the Cisterns

简单的二分,先判断给的水是否超过所有的盒子的容量,然后对最高的盒子的上界和最低的盒子的下界进行二分,直到h-l满足给定的条件跳出,只需要再加一个中间状态算总的水的体积的函数即可,代码如下: incl...

POJ1434-Fill the Cisterns!

Fill the Cisterns! Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 3197...

poj模拟题(二分查找)

  • 2014年07月22日 19:32
  • 420KB
  • 下载

BS EN 1434-6-2007

  • 2014年03月24日 08:23
  • 197KB
  • 下载

HDU1434(优先级队列)

幸福列车 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Su...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 1434 Fill the Cisterns! (二分)
举报原因:
原因补充:

(最多只允许输入30个字)