375_please tell me why get wa?

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

Moderator: Board moderators

375_please tell me why get wa?

Postby i see » Sat May 19, 2012 7:50 am

[quote][/quote]I think it should be correct,but the truth is not.please help me,thanks in advance!
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#define pi 3.1415926
//#define LOCAL
#define fin cin
#define fout cout
using namespace std;
double circumference(double b,double h)
{
double r,l,sum=0;
r=h*b/(b+sqrt(4*h*h+b*b));
if(r>=0.000001)
{
sum=sum+2*pi*r;
b=b-2*r*b/h;
h=h-2*r;
return sum+circumference(b,h);
}
else return 0;
}
int main()
{
#ifdef LOCAL
ifstream fin("in.cpp");
ofstream fout("out.cpp");
#endif
int t;
fin>>t;
double h,b;
while(t--)
{
fin>>b>>h;
fout<<setiosflags(ios::fixed)<<setprecision(6)<<setw(13)<<circumference(b,h)<<endl;
if(t!=0) fout<<endl;
}
return 0;
}
i see
New poster
 
Posts: 9
Joined: Sat May 19, 2012 7:35 am

Re: 375_please tell me why get wa?

Postby brianfry713 » Mon May 21, 2012 10:59 pm

Your PI doesn't have enough precision. Use M_PI instead.
brianfry713
Guru
 
Posts: 1754
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 375_please tell me why get wa?

Postby i see » Fri Jun 01, 2012 4:06 pm

thank you ! I have passed the problem with your helps!
i see
New poster
 
Posts: 9
Joined: Sat May 19, 2012 7:35 am


Return to Volume III

Who is online

Users browsing this forum: No registered users and 0 guests