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 2104【整体二分】

整体二分的想法就是将操作进行分块,将相互影响的操作放在一块。这题要注意分治结束条件 在没有离散化的情况下,就要以操作判断结束条件,当然这题操作数比较小,这样的话也更快。 下面的姿势是重排下标,总感...
  • u013007900
  • u013007900
  • 2015年08月27日 22:28
  • 794

NYOJ 586 疯牛 & POJ 2456(二分搜索 + 贪心)

疯牛 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述农夫 John 建造了一座很长的畜栏,它包括N (2 但是,John的C (2 输入有多组测试数据,...
  • LYHVOYAGE
  • LYHVOYAGE
  • 2014年04月09日 13:19
  • 4017

poj 3692 (二分图最大团)

Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4026   A...
  • sdjzujxc
  • sdjzujxc
  • 2013年02月20日 10:25
  • 1305

POJ 2976 Dropping tests(二分搜索,最大化平均值)

 Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Su...
  • zwj1452267376
  • zwj1452267376
  • 2015年12月04日 19:00
  • 306

POJ1469_COURSES(二分图最大匹配)

解题报告 题意: n个学生p门课程,每个学生学习0或1以上的课程。 问:是否可以组成委员会,满足 每个学生代表一门不同的课程 一门课程在委员会中有一名代表 思路: 很明显的二分图的完备匹配。 #inc...
  • u013320038
  • u013320038
  • 2014年07月26日 01:57
  • 846

【POJ 2892】 Tunnel Warfare(树状数组+二分)

【POJ 2892】 Tunnel Warfare(树状数组+二分) Time Limit: 1000MS   Memory Limit: 131072K To...
  • ChallengerRumble
  • ChallengerRumble
  • 2016年02月26日 17:23
  • 1339

POJ 1469 COURSES(二分图最大匹配)

POJ 1469 COURSES(二分图最大匹配) http://poj.org/problem?id=1469 题意:        有P门课和N个学生,每门课可能有0个或多个学生选修想选.现在问你...
  • u013480600
  • u013480600
  • 2014年08月15日 20:10
  • 795

POJ 3273 二分求最大化最小值

Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20086 Accep...
  • qq_22902423
  • qq_22902423
  • 2016年01月28日 16:12
  • 1837

poj 3020(二分图最小路径覆盖,拆点)

题目链接题目描述: Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8534 ...
  • fouzhe
  • fouzhe
  • 2016年07月26日 20:15
  • 418

poj2773(欧拉函数的应用 或者 用容斥原理+dfs+二分)

题意:给出m和k,求与m互质的第k个数 要用到的zh
  • u013509299
  • u013509299
  • 2014年05月03日 19:51
  • 791
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 1434 Fill the Cisterns! (二分)
举报原因:
原因补充:

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