## 10195 - The Knights Of The Round Table

Moderator: Board moderators

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
Do you consider a or b or c equal to 0 ?

Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Daredevil
New poster
Posts: 19
Joined: Tue Apr 01, 2003 7:47 am
Location: Earth
You mean one of them (a,b,c) or both ((a,b),(b,c),(a,c)) or the three of them are zeroes?
And what if these zeroes occur? should I ignore this input (since it can produce negative result in the sqrt which is undefined) ?

kmhasan
Problemsetter
Posts: 107
Joined: Fri Oct 26, 2001 2:00 am
Contact:
If a=0 OR b=0 OR c=0 (any of them is zero, all of them are zero, anything) the output would be zero.

Daredevil
New poster
Posts: 19
Joined: Tue Apr 01, 2003 7:47 am
Location: Earth
Got AC now!!!!
But when either of the side is 0, would that be a triangle? It should be a line instead of a triangle!!
But THANK YOU VERY MUCH !!!!!
Have a nice life !!

BiK
Experienced poster
Posts: 104
Joined: Tue Sep 23, 2003 5:49 pm

### Special cases

Actually, the special case with only one of a, b and c equal to zero is only possible for the non-zero lengths being equal. (Because of the condition max{a,b,c}<=(a+b+c)/2). In this case the radius is zero by the used and already discussed Heron-formule.
Actually, the really bad case is the case a=b=0, c>0! Then sqrt(something<0) is not defined!!!

Am I right?

Stefan for the BiK Team

BarteQ
New poster
Posts: 2
Joined: Mon Nov 24, 2003 10:39 pm
Location: POLAND

### 10195 WA why ????

My code in C++ is:

#include <stdio.h>
#include <math.h>

int main()
{ double a,b,c;
double S;
double p;
while(scanf("%lf %lf %lf", &a, &b, &c)==3)
{
if(a!=0 && b!=0 && c!=0)
{
p = (a+b+c)/2;
S=sqrt((p-a)*(p-b)*(p-c)/p);
printf("The radius of the round table is: %.3lf\n",S);
}
else
printf("The radius of the round table is: 0\n");

}
return 0;
}

and I still get WA. Why ?

Thx for any response[cpp][/cpp]

BarteQ
New poster
Posts: 2
Joined: Mon Nov 24, 2003 10:39 pm
Location: POLAND

### 10195 WA why ????

My code in C++ is:

#include <stdio.h>
#include <math.h>

int main()
{ double a,b,c;
double S;
double p;
while(scanf("%lf %lf %lf", &a, &b, &c)==3)
{
if(a!=0 && b!=0 && c!=0)
{
p = (a+b+c)/2;
S=sqrt((p-a)*(p-b)*(p-c)/p);
printf("The radius of the round table is: %.3lf\n",S);
}
else
printf("The radius of the round table is: 0\n");

}
return 0;
}

and I still get WA. Why ?

Thx for any response[cpp][/cpp]

neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba

### 10195 WA Pliz Help...!!!

Hello, I 've tried to solve P10195 several times, but it gives WA, what is wrong with my code? I have also checked the case that a == 0 or b == 0 or c == 0, here is my code:

[cpp]
#include <stdio.h>
#include <math.h>

int main()
{
double a, b, c, s;

while (scanf("%lf %lf %lf", &a, &b, &c) != EOF) {

if (a != 0 && b != 0 && c != 0) {

s = (a + b + c) / 2;
s = sqrt((s-a)*(s-b)*(s-c)/s);
printf("The radius of the round table is: %0.3lf\n", s);
}
else
printf("The radius of the round table is: 0\n");
}

return 0;
}
[/cpp]

I am frustrated neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba
I just made some changes in my code, now got AC ...!!!
WA was given due to precission errors, I think...

However you may find this lines very useful:

while (scanf(

usman
New poster
Posts: 1
Joined: Mon Jun 21, 2004 11:46 pm

### 10195 what is the problem with my code

Hello, I 've tried to solve 10195 several times, but it gives wrong answer, what is wrong with my code?

I have also checked the case that a == 0 or b == 0 or c == 0, here is my code, and also check that the side are of made triangle or not i uses law of cos , i also check the limits of input

C++:
[/cpp]
#include<stdio.h>
#include<math.h>

double a,b,c,s,alpha,beta,gama;

void main(){

while(scanf("%lf %lf %lf",&a,&b,&c)!=EOF)
{
if(a>=1 && a<=1000000 && b >=1 && b<=1000000 && c>=1 &&c<=1000000)
{
beta = (double) acos(((c*c)+(a*a)-(b*b))/(2*a*c));
alpha = (double) acos(((b*b)+(c*c)-(a*a))/(2*b*c));
gama = (double) acos(((a*a)+(b*b)-(c*c))/(2*a*b));
if(beta+alpha+gama==180.00 || beta+alpha+gama >=179.60 ||beta+alpha+gama <=180.00 )
{
s=(a+b+c)/2;a=sqrt((s-a)*(s-b)*(s-c)/s);
printf("The radius of the round table is: %.3lf\n",a);
}
}
}
}

mattapayne
New poster
Posts: 8
Joined: Thu Jun 17, 2004 5:50 am

### 10195 - Must be something really obvious

What am I missing here?:
[C++]

#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
while(cin >> a >> b >> c)
{
if(a>0 && a<=1000000 && b >0 && b<=1000000 && c>0 &&c<=1000000)
{
peri = (a + b + c) / 2;
radius = sqrt((peri - a) * (peri - b) * (peri - c) / peri);
cout << setiosflags(ios::fixed) << setprecision(3) << "The radius of the round table is: " << radius << "\n";
}
else
exit(1);
}
return 0;
}

Thanks,
Matt

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
To mattapayne :

The values of a b or c can be zero...
and if either of them is zero then the answer is also zero... .. but you seemed to return from the main function when any of the three
inputs is zero. And this line is irrelevant..
[c]
if(a>0 && a<=1000000 && b >0 && b<=1000000 && c>0 &&c<=1000000)
[/c] Since the problemset says No triangle size will be greater than 1000000 , you can safely assume they won't give you numbers more than this limit.

I have changed this two parts of your code and got AC.
Hope it helps. mattapayne
New poster
Posts: 8
Joined: Thu Jun 17, 2004 5:50 am
You are right. Got AC. Thanks.

Matt

Sifu
New poster
Posts: 1
Joined: Fri Jul 23, 2004 10:07 pm
I think you were on the right track but made some unnecessary checking.....
It should be something like this
[/cpp]
//10195
// knights of the round table

#include <stdio.h>
#include <iostream.h>
#include <math.h>
void main()
{
double a,b,c,s,r;
while (cin>>a>>b>>c)
{

if(a==0.0||b==0.0||c==0.0)
printf("The radius of the round table is: 0.000\n");
else
{
s=(a+b+c)/2;
if(s<0)
s = s* -1;

r=(s-a)*(s-b)*(s-c)/s;
r=sqrt(r);
printf("The radius of the round table is: %.3lf\n", r);
}
}

} Try this and see whether it works....... Take care and best of luck J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am