[UVA][Math] 11909 - Soya Milk
On the dining table we have a packet of soya milk. We can look at the packet as a rectangular box with height h, length l and width w. We tilt it against a base edge, as shown in the picture. Soya milk then comes out through the opening in the top face. This process stops when the milk level is no longer higher than the opening.
Write a program that computes the volume of soya milk remaining in the packet.
Note that the problem description may not perfectly match the real-life situation, but to solve this problem you must follow our assumptions.
Input
Each input file contains multiple test cases, and each test case starts on a new line.
Each case consists of four positive integers l, w, h (in centimetres) and θ (in degrees), all strictly less than 90.
Output
For each test case, output a line containing the volume of soya milk inside the packet in millilitres, correct to 3 decimal places.
Sample Input
9 6 19 20
Sample Output
937.555 mL
#include <stdio.h>
#include <math.h>
int main() {
int l, w, h, theta;
while(scanf("%d %d %d %d", &l, &w, &h, &theta) == 4) {
double b = theta/360.0 * 2 * acos(-1);
if(l*tan(b) <= h)
printf("%.3lf mL\n", l*w*h - w*0.5*l*l*tan(b));
else
printf("%.3lf mL\n", w*0.5*h*h*1/tan(b));
}
return 0;
}