1066 - Problem: Water Tanks

The Aqua Container Management company manages water storage facilities. They are considering a system of storing water in a series of connected vertical tanks. Each tank has a horizontal cross-sectional area of one square meter, but the tanks have different heights. The base of each tank is at ground level. Each tank is connected by a pipe to the previous tank in the series and by another pipe to the next tank in the series. The pipes connecting the tanks are level and are at increasing heights (that is, the pipe connecting tank i to tank i + 1 is at a higher level than the pipe connecting tank i to tank i - 1 .) Tank 1 is open so that air and water can flow into it freely at the top. All the other tanks are closed so that air and water can flow in and out only through the connecting pipes. The connecting pipes are large enough that water and air can flow through them freely and simultaneously but small enough that their dimensions can be ignored in this problem.

The series of tanks is filled by pouring water slowly into the top of tank 1, continuing until the water level reaches the top of tank 1. As the water level rises above the connecting pipes, water flows among the tanks.

Aqua Container Management needs a program to compute the cubic meters of water that can be poured into the series of tanks before the water level reaches the top of tank 1.

The figure below illustrates a simple case involving only two tanks. After the filling procedure is completed, the air in the upper part of the second tank is compressed (its air pressure is greater than one atmosphere), so the water level in the second tank is lower than the water level in the first tank.

\epsfbox{p3810.eps}

The following physical principles are helpful in solving this problem (some of these are approximations that are acceptable for the purposes of this problem):

  • Water flows downhill.
  • In an open space, the air pressure is equal to one atmosphere.
  • Air is compressible (the volume occupied by a given amount of air depends on pressure). Water is not compressible (the volume occupied by a given amount of water is constant, independent of pressure).
  • Air pressure is the same everywhere within a closed space. If the volume of the closed space changes, the product of the volume and the air pressure within the space remains constant. For example, suppose an enclosed airspace has an initial volume V1 and pressure P1 . If the volume of the airspace changes to V2 , then the new pressure P2 satisfies P1V1 = P2V2 .
  • In a column of water below an airspace, the water pressure at a level D meters below the water surface is equal to the air pressure at the surface plus 0.097 . D atmospheres. This is true regardless of whether the airspace is open or enclosed.
  • In a connected body of water (for example, when two or more tanks are connected by pipes below the water line), the water pressure is constant at any given level.

Input 

The input consists of several test cases representing different series of water tanks. Each test case has three lines of data. The first line contains an integer N (2$ \le$N$ \le$10) which is the number of tanks in the test case. The second line contains N positive floating point numbers that are the heights, in meters, of tanks 1 through N . The third line contains N - 1 floating point numbers. On this line, the k th number represents the height above the ground of the pipe that connects tank k and tank k + 1 . The numbers on the third line are increasing (each number is greater than the preceding number).

The last test case is followed by a line containing the integer zero.

Output 

For each test case, print a line containing the test case number (beginning with 1) followed by the amount of water, in cubic meters, that can be poured into tank 1 before the water level reaches the top of tank 1. Print the results with three digits to the right of the decimal point.

Print a blank line after the output for each test case. Use the format of the sample output.

Sample Input 

2 
10.0 8.0 
4.0 
0

Sample Output 

Case 1: 15.260









#include<stdio.h>
#include<math.h>
int n,i,cases;
double tank[11],pipe[11],h0,dh,V,V0,p,k,sum;
double root(double b,double c)
{
	return b/2-sqrt(b*b/4-c);
}

int main()
{
	k=0.097;
	while(scanf("%d",&n)&&n)
	{
		V=0;
		for(i=0;i<n;i++)
		{
			scanf("%lf",&tank[i]);
			if(i)
				V+=tank[i];
		}
		for(i=1;i<n;i++)
			scanf("%lf",&pipe[i]);
		V-=pipe[1];
		p=1;
		sum=pipe[1];
		for(i=1;i<n;i++)
		{
			dh=pipe[i+1]-pipe[i];
			if(i<n-1)
				h0=pipe[i+1] + (p*V/(V-dh)-1)/k;
			if(h0>tank[0]||i==n-1)
			{
				dh=tank[0]-pipe[i];
				sum+=root(dh+V+1/k,dh*V+(1-p)*V/k);
				break;
			}
			sum+=dh;
			p*=V/(V-dh);
			V-=dh;
			h0=pipe[i+1] + (p*V/(V-pipe[i+1])-1)/k;

			if(h0>tank[0])
			{
				sum+=V-V*p/(1+(tank[0]-pipe[i+1])*k);
				break;
			}
			p*=V/(V-pipe[i+1]);
			V-=tank[i];
			V0=tank[i]-pipe[i+1];
			dh=tank[0]-pipe[i+1];
			sum+=pipe[i+1] + root(dh + V0+1/k, dh*V0 + (1-p)*V0/k);
		}
		printf("Case %d: %.3lf\n\n",++cases,sum+tank[0]);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值