## 375 - Inscribed Circles and Isosceles Triangles

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

Moderator: Board moderators

zhangfei
New poster
Posts: 5
Joined: Thu Jul 29, 2010 2:08 pm

### 375

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

nirupam
New poster
Posts: 1
Joined: Mon Jul 26, 2010 10:11 pm

### Re: 375

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

i see
New poster
Posts: 9
Joined: Sat May 19, 2012 7:35 am

### 375_please tell me why get wa?

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 375_please tell me why get wa?

Your PI doesn't have enough precision. Use M_PI instead.
Check input and AC output for thousands of problems on uDebug!

i see
New poster
Posts: 9
Joined: Sat May 19, 2012 7:35 am

### Re: 375_please tell me why get wa?

thank you ! I have passed the problem with your helps!