## 10195 - The Knights Of The Round Table

Moderator: Board moderators

Max
New poster
Posts: 2
Joined: Sat Nov 17, 2001 2:00 am

### 10195 - The Knights Of The Round Table

Why does this code get W.A.?

#include <math.h>
#include <iostream.h>
#include <iomanip.h>

long double a, b, c, p;

main(){
cout << setiosflags(ios::fixed) << setprecision(3);
while (cin >> a >> b >> c){
p = (a+b+c)/2;
cout << "The radius of the round table is: "
<< sqrt( (p-a)*(p-b)*(p-c)/p ) << endl;
}
}

arnsfelt
New poster
Posts: 44
Joined: Wed Oct 17, 2001 2:00 am
Location: Denmark
Contact:
Try to make it a special case when one of the input values is 0.

Kristoffer Hansen

Max
New poster
Posts: 2
Joined: Sat Nov 17, 2001 2:00 am
Thanks

necropower
New poster
Posts: 20
Joined: Wed Dec 26, 2001 2:00 am
(my keyboard is with a problem in the interrogation key, i will be using @ instead)

can u tell me how did u find these equations for the answer@
i couldnt figure it out using math...

thanks,
Necropower

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:
Maybe he just looked it up, just like I did... I guess I would've used some sin/cos/tan stuff if I had been on my own.

http://mathworld.wolfram.com/Triangle.html
http://mathworld.wolfram.com/Incircle.html

That's a very useful, great site, btw...

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:
And the special case is meaner (= even more unrealistic) than having one side length equal to zero. I hate these descriptions with a real life story behind them and then special cases that are so non-real-life. That's simply crap. My personal opinion. I don't like it when somebody purposely fools me.

<font size=-1>[ This Message was edited by: Stefan Pochmann on 2002-03-25 19:37 ]</font>

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

### argh

I just can't stop getting WA on this. I have tried all kinds of possibilities. Here is my current code:

[c]removed........spoiler [/c]

Any comments ? What test cases have I missed or is this just a precision problem. I have tried using long double/float and double, I have tried checking variables for 0 or for >0, and I have tried calculating negative circles for negative lengths...... this is annoying me now
Last edited by Caesum on Mon May 13, 2002 6:40 pm, edited 1 time in total.

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:
This is just a guess, but it might be a good idea to follow the instructions and write "The radius of the round table is: " in front of the numbers.

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:
omg...... having a bad day i think

yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am
I can't how one of the input may be zero. The question says that it will be a triangle. But how can one of the length might be zero? if zero will it be a triangle then?

avlahov
New poster
Posts: 5
Joined: Wed Nov 07, 2001 2:00 am

### What's Wrong?

i can't think of a possible special case...

also if i input 34.64 34.64 34.64 should i get 10.000 or 10?

#include <iostream.h>
#include <math.h>

void main()
{
long double a, b, c;

while(cin>>a>>b>>c)
{
long double p = (a + b + c)/2;

long double temp = p*(p-a)*(p-b)*(p-c);

long double s = sqrtl(temp);

long double r = s/p;

cout.setf(ios::fixed|ios::showpoint);
cout.precision(3);

if((a==0.0)||(b==0.0)||(c==0.0))
cout<<"The radius of the round table is: 0.000"<<endl;
else
cout<<"The radius of the round table is: "<<r<<endl;

}
}

xenon
Learning poster
Posts: 100
Joined: Fri May 24, 2002 10:35 am
Location: Scheveningen, Holland
Since I don't believe programming should be a guessing game (I fully agree with Stefan's objections above) and I did my portion of guessing on this problem, I'll take away the dirtyness by publishing the part of my code that deals with it:
[pascal]program p10195(input,output);

var
a,b,c,r:double;
begin
while not eof(input) do begin
if (a*b*c=0) then begin
if (a<>0) then r:=a/2
else if (b<>0) then r:=b/2
else r:=c/2;
end
else begin
{The intelligent part of the code that calculates r
for a proper triangle}
end;
writeln('The radius of the round table is: ',r:0:3);
end;
end.[/pascal]
I got it AC, so there is no rounding problem.

A very frustrated,
- xenon

arnsfelt
New poster
Posts: 44
Joined: Wed Oct 17, 2001 2:00 am
Location: Denmark
Contact:
AFAIK it suffices to just output 0 when one of a,b,c is 0.

xenon
Learning poster
Posts: 100
Joined: Fri May 24, 2002 10:35 am
Location: Scheveningen, Holland
That might be, and I take your word for it. I was tired of guessing, so I didn't verify that if one of a,b,c is zero then they all are zero.

My solution also solves the 'general case' where the triangle (x,x,0.0) is really a line of length x. In that case the table is a circle with radius x/2.

But hey, bullshit remains bullshit, even if you pull it to a higher level.

-xenon

Daredevil
New poster
Posts: 19
Joined: Tue Apr 01, 2003 7:47 am
Location: Earth

### 10195 - Why WA?

What's wrong with my program?

C :

#include<stdio.h>
#include<math.h>
double a,b,c,s;
void main(){
while(scanf("%lf %lf %lf",&a,&b,&c)!=EOF){
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);
}
}

Any comment is appreciated.
[/quote][/c]