Page 1 of 4
10195 - The Knights Of The Round Table
Posted: Sat Nov 17, 2001 4:45 pm
by Max
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;
}
}
Posted: Sat Nov 17, 2001 10:30 pm
by arnsfelt
Try to make it a special case when one of the input values is 0.
Kristoffer Hansen
Posted: Sun Nov 18, 2001 12:32 am
by Max
Thanks
Posted: Mon Mar 25, 2002 3:18 pm
by necropower
(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
Posted: Mon Mar 25, 2002 8:13 pm
by Stefan Pochmann
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...
Posted: Mon Mar 25, 2002 8:28 pm
by Stefan Pochmann
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>
argh
Posted: Mon May 13, 2002 12:36 am
by Caesum
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

Posted: Mon May 13, 2002 10:59 am
by Stefan Pochmann
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.
Posted: Mon May 13, 2002 6:40 pm
by Caesum
omg...... having a bad day i think

Posted: Thu Jun 13, 2002 4:09 pm
by yahoo
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?
What's Wrong?
Posted: Tue Jul 16, 2002 2:33 pm
by avlahov
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;
}
}
Posted: Fri Aug 09, 2002 10:26 pm
by xenon
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
Posted: Fri Aug 09, 2002 11:42 pm
by arnsfelt
AFAIK it suffices to just output 0 when one of a,b,c is 0.
Posted: Fri Aug 09, 2002 11:53 pm
by 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
10195 - Why WA?
Posted: Tue Apr 01, 2003 7:54 am
by Daredevil
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]