## 10175 - Sphere

Moderator: Board moderators

liusu
New poster
Posts: 22
Joined: Thu Aug 01, 2002 10:26 am

### 10175 - Sphere

who can help me?i can't find mistake.could you help?
thank you...

[pascal]var
r1,r2:integer;
d,w,s,pi:real;
v,ba:real;
sumcase,i:integer;
function volume(r,h:real):real;
begin
volume:=pi*h*(h*h+3*r*r)/6;
end;
function surarea(r,h:real):real;
begin
surarea:=pi*(h*h+r*r);
end;
function isfloat:boolean;
begin
if w/v<=s then isfloat:=true
else isfloat:=false;
end;
procedure slv;
var
h2,r,h1:real;
begin
h1:=r1-(r1*r1+d*d-r2*r2)/(2*d);
r:=sqrt(r1*r1-sqr((r1*r1+d*d-r2*r2)/(2*d)));
h2:=r2-(r2*r2+d*d-r1*r1)/(2*d);
v:=volume(r,2*r1-h1)+volume(r,2*r2-h2);
ba:=surarea(r,2*r1-h1)+surarea(r,2*r1-h2);
writeln(v:4:4,' ',ba:4:4);
if isfloat=true then writeln('The Paired-Sphere Floats.')
else writeln('The Paired-Sphere Sinks.');
end;
begin
pi:=4*arctan(1.0);
for i:=1 to sumcase do
begin
slv;
end;
end.[/pascal]

dwyak
New poster
Posts: 36
Joined: Sun Jul 28, 2002 5:16 am
Location: P.R.China
Contact:
I got WA too. And here is my program
[cpp]#include <fstream.h>
#include <math.h>

//ifstream fin("10175.txt");
#define fin cin
#define endl '\n'

const double PI = acos(0.0) * 2;

main() {
cout.precision(4);
cout.setf(ios::fixed, ios::floatfield);
int cases, pcase;
fin >> cases;
for (pcase = 0; pcase < cases; pcase++) {
double r1, r2, d, w, s, h1, h2, tmp;
fin >> r1 >> r2 >> d >> w >> s;
h1 = (r1 * r1 - r2 * r2 + d * d) / 2 / d;
h2 = d - h1;
h1 += r1, h2 += r2;

double V = PI * h1 * h1 * (r1 - h1 / 3) + PI * h2 * h2 * (r2 - h2 / 3);
double S = 2 * PI * r1 * h1 + 2 * PI * r2 * h2;

cout << V << ' ' << S << endl;
if (V / w > s - 1e-8)
cout << "The Paired-Sphere Floats." << endl;
else
cout << "The Paired-Sphere Sinks." << endl;
}

return 0;
}[/cpp]
Wenyuan Dai, Shanghai Jiaotong University.

Antonio Ocampo
Experienced poster
Posts: 131
Joined: Sat Jul 17, 2004 4:09 am
Location: Lima, Per

### 10175: Sphere

Hi fellows, could someone give me any critical I/O in order to solve this problem?.

I got WA with this code:

Code: Select all

``````
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
int n;
double r1,r2,d,w,s;
double pi=2.0*acos(0.0),h1,h2,v,a;

scanf("%i",&n);

do
{
scanf("%lf%lf%lf%lf%lf",&r1,&r2,&d,&w,&s);

h1 =0.5*(r1 * r1 - r2 * r2 + d * d)/d;
h2 =d - h1;
h1+=r1;
h2+=r2;

v = pi*h1*h1*(r1-h1/3) + pi*h2*h2*(r2 - h2 / 3);
a= 2*pi*(r1*h1+r2*h2);

printf("%.4lf %.4lf\n",v,a);

if( v-w*s>1e-9 )
puts("The Paired-Sphere Floats.");

else
puts("The Paired-Sphere Sinks.");
}
while(--n);

return 0;
}

``````

Antonio Ocampo
Experienced poster
Posts: 131
Joined: Sat Jul 17, 2004 4:09 am
Location: Lima, Per

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
``````if( w/v<s || (w/v-s)<EPS )