[UVA] 697 - Jack and Jill
Jack and Jill
Jack and Jill |
Jack and Jill went up the hill to fetch a pail of water. Well, they probably need to fetch many pails of water in this problem. The problem is to determine how long it will take Jack and Jill to fetch a specified volume of water.
Jack and Jill require UP seconds (always greater than one) to travel
from the bottom of the hill to the top, where the well is located. The well
is a circular cylinder with a diameter of D inches, and before any
water is removed, the water level is L inches below its top.
The single bucket, with a capacity of B cubic feet, when dropped into
the well (with a rope attached, of course) accelerates at 32.2 feet per
second per second (due to gravity). The bucket is pulled up at a rate
of P inches per second. It requires DOWN seconds to carry the
bucket to the bottom of the hill and empty it.
Jack and Jill begin at the bottom of the hill. They both immediately go
to the top of the hill, where Jill fetches water from the well: dropping
the bucket (which we assume will immediately fill completely when it
reaches the water), pulling it up, and passing it to Jack (instantaneously).
Assume the water level in the well drops only after the bucket is lifted.
Jack then carries the bucket down the hill, empties it (instantaneously), goes
back up the hill, and gives the bucket to Jill (instantaneously). This process repeats
until the required volume of water (V cubic feet) has been carried
to the bottom of the hill.
The problem, again, is to determine how long it takes Jack and Jill to accomplish their task.
Input
The input contains multiple scenarios, each having values for UP, D, L, B, P, DOWN, and V (all positive non-zero real numbers) in that order on a separate line.A line containing a single value less than one appears following the data for the last scenario.
Output
For each scenario, display the scenario number (they start with 1 and are numbered sequentially), the input values, and the time required, in seconds (accurate to two fractional digits). The samples shown below illustrate an acceptable output format. Print a blank line between test cases. By the way, you can assume the well never runs dry, even though its volume only diminishes during Jack and Jill's activities!
Sample Input
20.0 36.0 72.0 2.0 10.0 18.0 10.0 25.0 72.0 200.0 1.5 8.0 30.0 20.0 0.0
Sample Output
Scenario 1: up hill 20.00 sec well diameter 36.00 in water level 72.00 in bucket volume 2.00 cu ft bucket ascent rate 10.00 in/sec down hill 18.00 sec required volume 10.00 cu ft TIME REQUIRED 232.59 sec Scenario 2: up hill 25.00 sec well diameter 72.00 in water level 200.00 in bucket volume 1.50 cu ft bucket ascent rate 8.00 in/sec down hill 30.00 sec required volume 20.00 cu ft TIME REQUIRED 1141.63 sec
Miguel Revilla
2000-08-14
爬上山的時間為 UP, 一開始井口離水面高度 L, 桶子的容量 B, 把桶子從井底拉上的速度 P
下山的時間為 DOWN, 井口直徑 D, 目標要裝的水容量 V
求最少時間,即最少趟。
每次當桶子碰到水面時,會立即裝滿水,而拉起時,水面會下降。
直接模擬多少趟即可,雖然題目沒有給數據範圍,不過也沒有 TLE 的情況發生。
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
//1 feet = 12 inch
int main() {
double UP, D, L, B, P, DOWN, V;
const double pi = acos(-1);
int cases = 0;
while(scanf("%lf", &UP) == 1) {
if(UP < 1) break;
scanf("%lf %lf %lf %lf %lf %lf", &D, &L, &B, &P, &DOWN, &V);
int runtime = (int)ceil(V/B - 0.000000000001);
int i, j, k;
double time = 0, oL = L;
for(i = 0; i < runtime; i++) {
time += UP+DOWN;
time += sqrt(2*L/(32.2*12));
time += L/P;
L += 4*B*12*12*12/(D*D*pi);
}
if(cases) puts("");
printf("Scenario %d:\n", ++cases);
printf(" up hill %10.2lf sec\n", UP);
printf(" well diameter %10.2lf in\n", D);
printf(" water level %10.2lf in\n", oL);
printf(" bucket volume %10.2lf cu ft\n", B);
printf(" bucket ascent rate%8.2lf in/sec\n", P);
printf(" down hill %10.2lf sec\n", DOWN);
printf(" required volume %10.2lf cu ft\n", V);
printf(" TIME REQUIRED %10.2lf sec\n", time);
}
return 0;
}