10195  The Knights Of The Round Table
Moderator: Board moderators
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( (pa)*(pb)*(pc)/p ) << endl;
}
}
#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( (pa)*(pb)*(pc)/p ) << endl;
}
}

 New poster
 Posts: 20
 Joined: Wed Dec 26, 2001 2:00 am

 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/Inradius.html
see also:
http://mathworld.wolfram.com/Triangle.html
http://mathworld.wolfram.com/Incircle.html
That's a very useful, great site, btw...
http://mathworld.wolfram.com/Inradius.html
see also:
http://mathworld.wolfram.com/Triangle.html
http://mathworld.wolfram.com/Incircle.html
That's a very useful, great site, btw...

 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 nonreallife. 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 20020325 19:37 ]</font>
<font size=1>[ This Message was edited by: Stefan Pochmann on 20020325 19:37 ]</font>
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
[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.

 A great helper
 Posts: 284
 Joined: Thu Feb 28, 2002 2:00 am
 Location: Germany
 Contact:
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*(pa)*(pb)*(pc);
long double s = sqrtl(temp);
long double r = s/p;
cout.setf(ios::fixedios::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;
}
}
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*(pa)*(pb)*(pc);
long double s = sqrtl(temp);
long double r = s/p;
cout.setf(ios::fixedios::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;
}
}
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
readln(a,b,c);
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
[pascal]program p10195(input,output);
var
a,b,c,r:double;
begin
while not eof(input) do begin
readln(a,b,c);
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
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
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
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((sa)*(sb)*(sc)/s);
printf("The radius of the round table is: %.3lf\n",a);
}
}
Any comment is appreciated.
[/quote][/c]
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((sa)*(sb)*(sc)/s);
printf("The radius of the round table is: %.3lf\n",a);
}
}
Any comment is appreciated.
[/quote][/c]