10175 - Sphere

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

10175 - Sphere

Post by liusu » Tue Aug 13, 2002 2:29 pm

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

[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
readln(sumcase);
pi:=4*arctan(1.0);
for i:=1 to sumcase do
begin
readln(r1,r2,d,w,s);
slv;
end;
readln;
end.[/pascal]

dwyak
New poster
Posts: 36
Joined: Sun Jul 28, 2002 5:16 am
Location: P.R.China
Contact:

Post by dwyak » Fri Sep 13, 2002 9:58 am

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

Post by Antonio Ocampo » Fri Aug 12, 2005 1:58 am

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;
}

Thx in advance :wink:

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

Post by Antonio Ocampo » Mon Aug 15, 2005 2:30 am

Please help me!!!! :cry: I'm so frustrated :oops:

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon » Wed Dec 28, 2005 1:08 am

Hi,

try this,

Code: Select all

if( w/v<s || (w/v-s)<EPS )
  puts("The Paired-Sphere Floats."); 
else
  puts("The Paired-Sphere Sinks."); 
with EPS=1e-17 or some small number.

Post Reply

Return to “Volume 101 (10100-10199)”