Page 2 of 2
375
Posted: Mon Aug 02, 2010 12:41 pm
by zhangfei
The PI uses asin(1.0)*2 instead of 3.14159265 for the precision.Pay attention to the precision when you will add all radius of circle.
Here is my AC code.
Code: Select all
#include <stdio.h>
#include <math.h>
#define PI asin(1.0)*2
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int nCase;
double B,H;
scanf("%d",&nCase);
while(nCase--)
{
scanf("%lf%lf",&B,&H);
double L = sqrt(H*H+B*B/4);
double R = B*H/(2*L+B);
double h = H;
double r = R;
while(r >= 0.000001)
{
h -= 2*r;
r = h/H*R;
}
printf("%13lf\n",(H-h)*PI);
if(nCase)
putchar('\n');
}
return 0;
}
Re: 375
Posted: Fri Aug 27, 2010 5:38 am
by nirupam
Here is my code.I think L,R,B is Ok.But i get wrong answer for sample input.
i/p : 0.263451 0.263451
o/p : 0.827653 instead of 0.827648
whats wrong in my code.Anyone can help me?
Code: Select all
int main()
{
freopen("in.txt","r",stdin);
double B,H,R,SR,L;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf",&B,&H);
SR=0;
L=sqrt(H*H+B*B/4);
R=(B*H)/(B+2*L);
SR=SR+R;
while(R>=0.000001)
{
//update traingle
B=(H-2*R)*B/H;
H=H-2*R;
L=sqrt(H*H+B*B/4);
R=(B*H)/(B+2*L);
SR=SR+R;
}
if(T)
printf("%13lf",2*SR*acos(-1));
else
printf("%13lf\n",2*SR*acos(-1));
}
exit(0);
}
After getting 7 WA i found error and UVA judge reply me AC.
Thanks God
------------------------------------
375_please tell me why get wa?
Posted: Sat May 19, 2012 7:50 am
by i see
[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;
}
Re: 375_please tell me why get wa?
Posted: Mon May 21, 2012 10:59 pm
by brianfry713
Your PI doesn't have enough precision. Use M_PI instead.
Re: 375_please tell me why get wa?
Posted: Fri Jun 01, 2012 4:06 pm
by i see
thank you ! I have passed the problem with your helps!