24h購物| | PChome| 登入
2013-08-11 15:40:57| 人氣1,261| 回應0 | 上一篇 | 下一篇

[UVA][二分] 11692 - Rain Fall

推薦 0 收藏 0 轉貼0 訂閱站台

Problem D - Rain Fall

Time limit: X seconds

Rainfall is measured in millimeters. The rain is collected in a vertical transparent tube with millimeter markings, and once the rain has stopped falling, one can check the height of the water in the tube.

In our problem, the tube unfortunately has a leak at height L millimeters (mm). If the water level is above the leak then water drains from the tube at a rate of K millimeters per hour (mm/h).

We want to figure out how much rain fell during a particular rainfall. We assume that the tube is high enough that it does not overflow. We also assume that rain falls at an (unknown) uniform rate during a rainfall, and that water does not evaporate from the tube. The height of the leak itself is also negligible.

Input

The first line of the input file contains an integer N (N<40) which denotes the total number of test cases. The description of each test case is given below:

A line with five positive numbers: L K T1 T2 H where

  • L is where the leak is (mm)
  • K is the rate at which water leaks (mm/h)
  • T1 is the duration of the rainfall (h)
  • T2 is the time between the end of the rainfall and the observation of the water level (h)
  • H is the water level in the tube when we observe it (mm)
Each number is at least 0.01 and at most 1000.00, and each is given with two decimals.

Output

For each test case print one line with two floating point numbers F1 F2 where F1 is the smallest rainfall in millimeters that would result in the given observation, and F2 is the largest rainfall in millimeters that would result in the given observation. Values with either absolute or relative error smaller than 10-6 are acceptable.

Sample Input

2
80.00 0.50 2.00 1.50 80.00
150.00 1.00 100.00 150.00 100.00

Sample Output

80.000000 80.759403
100.000000 100.000000

The 2009 ACM Nordic Collegiate Programming Contest


給定水庫高 L, 超過高度 L 則會以 K 速率放水, 假設下雨時間 T1, 在 T1 後, 放水 T2 時間,
在 T1+T2 時刻觀察水位高度為 H。

假設下雨雨量平均分布於 T1 時間內,問降雨量最大最小分別為多少。

不會列式,先從二分著手。


#include <stdio.h>
#include <math.h>
int main() {
    int testcase;
    double L, K, T1, T2, H;
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%lf %lf %lf %lf %lf", &L, &K, &T1, &T2, &H);
        double l = 0, r = 1e+30, m;
        double mn, mx;
        while(fabs(l-r) > 1e-8) {
            m = (l+r)/2;
            double rate = m/T1;
            double f;
            if(m <= L)  f = m;
            else {
                double time = L/rate;
                if(K < rate)
                    f = L+(T1-time)*(rate-K);
                else
                    f = L;
                if(K*T2 > f-L)
                    f = L;
                else
                    f -= K*T2;
            }
            if(f > H)
                r = m;
            else
                l = m;
        }
        mx = m;
        l = 0, r = 1e+30;
        while(fabs(l-r) > 1e-8) {
            m = (l+r)/2;
            double rate = m/T1;
            double f;
            if(m <= L)  f = m;
            else {
                double time = L/rate;
                if(K < rate)
                    f = L+(T1-time)*(rate-K);
                else
                    f = L;
                if(K*T2 > f-L)
                    f = L;
                else
                    f -= K*T2;
            }
            if(f < H)
                l = m;
            else
                r = m;
        }
        mn = m;
        printf("%.6lf %.6lf\n", mn, mx);
    }
    return 0;
}

台長: Morris
人氣(1,261) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA] 377 - Cowculations
此分類上一篇:[UVA] 10964 - Strange Planet

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文