首页 > ACM题库 > HDU-杭电 > HDU 3142-Rain Fall[解题报告]HOJ
2014
03-03

HDU 3142-Rain Fall[解题报告]HOJ

Rain Fall

问题描述 :


Allergy Test

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.

输入:

The input is 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.

输出:

The input is 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.

样例输入:

80.00 0.50 2.00 1.50 80.00
150.00 1.00 100.00 150.00 100.00

样例输出:

80.000000000 80.759403280
100.000000000 100.000000000

#include<iostream>
#include<vector>
#include<fstream>
#include<queue>
#include<algorithm>
#include<list>
#include<cstdio>
#include<stack>
#include<cstring>
#include<cmath>
#include<string>
#include <functional>
#include<sstream>
#include<map>
using namespace std;
#define     For(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     FIT(it,v)         for (typeof((v).begin())it=(v).begin(); it!=(v).end(); ++it)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     GSORT(x)          sort(ALL(x), greater<typeof(*((x).begin()))>())
#define     UNIQUE(v)         SORT(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SF                scanf
#define     PF                printf
#define     MAXN               1001
#define     MAXM               1001
#define     MOD               1000000007
#define     Dbug             cout<<"";
#define     eps             1e-15

typedef long long ll;
typedef pair<int,int> pii;
int n;
double l, k, t1, t2, h;
bool u;
bool check(double r)
{
	double t0=l/r;
	t0=t1-t0;
	double r2=r-k;
	double w=l+(r2*t0);
	double le=t2*k;
	w-=le;
	if(w==h)
		u=1;
	if(w>=h) return 1;
	return 0;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//freopen("a.in","r",stdin);
	int tc;
	cin>>tc;
	while (tc--)
	{
		u=0;
		cin>>l>>k>>t1>>t2>>h;
		double ans, m, M, le=0, r=1<<30;
		if(h<l) 
		{
			PF("%.6lf %.6lf\n", h, h);
			continue;
		}
		while (fabs(le-r)>eps)
		{
			double mid=(le+r)/2.;
			if(check(mid)) 
				ans=mid, r=mid;
			else le=mid;
			if(u) break;
		}
		if(le<ans) if(check(le)) ans=le;
		r=ans;
		double t0=l/r;
		t0=t1-t0;
		//double r2=r-k;
		double w=l+(r*t0);
		if(h==l)
		{
			PF("%.6lf %.6lf\n", l, w);
		}
		else 
			PF("%.6lf %.6lf\n", w, w);
	}
	return 0;
}