10195 - The Knights Of The Round Table

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

Moderator: Board moderators

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

10195 - The Knights Of The Round Table

Post by Max » Sat Nov 17, 2001 4:45 pm

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:

Post by arnsfelt » Sat Nov 17, 2001 10:30 pm

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

Post by Max » Sun Nov 18, 2001 12:32 am

Thanks

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

Post by necropower » Mon Mar 25, 2002 3:18 pm

(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... :sad:

thanks,
Necropower

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Mon Mar 25, 2002 8:13 pm

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

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Mon Mar 25, 2002 8:28 pm

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

Post by Caesum » Mon May 13, 2002 12:36 am

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:

Post by Stefan Pochmann » Mon May 13, 2002 10:59 am

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:

Post by Caesum » Mon May 13, 2002 6:40 pm

omg...... having a bad day i think :oops:

User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

Post by yahoo » Thu Jun 13, 2002 4:09 pm

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?

Post by avlahov » Tue Jul 16, 2002 2:33 pm

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

Post by xenon » Fri Aug 09, 2002 10:26 pm

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

arnsfelt
New poster
Posts: 44
Joined: Wed Oct 17, 2001 2:00 am
Location: Denmark
Contact:

Post by arnsfelt » Fri Aug 09, 2002 11:42 pm

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

Post by xenon » Fri Aug 09, 2002 11:53 pm

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?

Post by Daredevil » Tue Apr 01, 2003 7:54 am

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]

Post Reply

Return to “Volume 101 (10100-10199)”