2007 ACM南京预赛C题
Ray’s Magic Ball
总提交:554 测试通过:95
描述
Ray has just borrowed the Magic Ball (MB) from Jiejie. The Magic Ball is a hollow metal ball whose thickness can be ignored. Although it is called Magic Ball, Jiejie still has no idea where the magic lies. Therefore, he sincerely asked Ray to demonstrate it in return for his lending.
It was a really long time before Ray has come up with an idea. First, he finds a way to fill the ball with a sort of liquid, then he hangs it in the air, and at the last and the most important step, he makes a small hole right at the bottom of the ball (the lowest point on the ball after its being hung). As you can imagine, the liquid begins to leak. Now Ray announced proudly, “God has told me of the depth of the remaining liquid when the center of the gravity of the whole ball (including the liquid) is lowest”. Can you also do it?
输入
The input contains multiple test cases. For each test case, there is only one line containing three integers (all less than 30000), representing the radius of the ball, the mass of the ball and the density of the liquid respectively.
输出
For each test case output one number indicating the depth of the remaining liquid, and output two digits after the decimal point.
样例输入
1 0 10000
样例输出
0.00
题目来源
NUAA
// team520 1117 Accepted 0MS 180K 743Byte G++ 2007-10-01 15:17:51.0
#include <stdio.h>
double R, mass, dest;
double const PI = 3.141592653589793;
inline double G(double Z) {
return dest* (PI*R*Z*Z - PI*Z*Z*Z/3);
}
inline double H(double Z) {
return Z*3/4 - R*Z/(12*R-4*Z);
}
inline double Y(double Z) {
double g = G(Z);
return (R*mass + H(Z)*g)/(g+mass);
}
int main() {
double guess;
double best;
double temp;
while( scanf("%lf %lf %lf", &R, &mass, &dest) != EOF ) {
if( mass == 0.0 ) {
printf("0.00\n");
continue;
}
best = R;
for(guess=0.00; guess<=R; guess+=0.01) {
temp = Y(guess);
if( best > temp ) {
best = temp;
}
}
printf("%.2lf\n", best);
}
}