438 - The Circumference of the Circle

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

Moderator: Board moderators

rmukadam
New poster
Posts: 4
Joined: Wed May 01, 2002 2:51 pm

Q438

Post by rmukadam » Thu May 02, 2002 1:51 am

I am using the following approach to compute the circumference:

ax^2+cy^2+dx+ey+f=0 as equa:

and center x=-d/2a y =-e/2a

a := Determinate (matrix([[X1, Y1, 1], [X2, Y2, 1], [X3, Y3, 1]]))

d := -Determinate(matrix([[X1^2+Y1^2, Y1, 1], [X2^2+Y2^2, Y2, 1], [X3^2+Y3^2, Y3, 1]]))

e := Determinate(matrix([[X1^2+Y1^2, X1, 1], [X2^2+Y2^2, X2, 1], [X3^2+Y3^2, X3, 1]]))

I'm pretty sure of the formulas and they do give me correct result. I have tested for lots of cases BUT i still get WA.......Any ideas what could be going wrong??.......Thanks.

udvat
New poster
Posts: 29
Joined: Thu Aug 07, 2003 9:56 pm

438.....why am getting out put limit ex????

Post by udvat » Fri Aug 08, 2003 8:26 pm

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


void main()
{
double x1,x2,x3,y1,y2,y3,a,b,c;
double p,q,r,p1,q1,r1,s,L,C;
double PI=3.141592653589793L;

x1=x2=x3=y1=y2=y3=a=b=c=0;
while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3))
{

p=(x1-x2);
q=(x2-x3);
r=(x3-x1);

p1=(y1-y2);
q1=(y2-y3);
r1=(y3-y1);

a=sqrt(pow(p,2)+pow(p1,2));
b=sqrt(pow(q,2)+pow(q1,2));
c=sqrt(pow(r,2)+pow(r1,2));

s=(a+b+c)/2.0;
p=(s-a);
q=(s-b);
r=(s-c);

L=sqrt(s*p*q*r);

r=(a*b*c)/L;
r=r/4;

C=2*PI*r;

printf("%.2f\n",C);
x1=x2=x3=y1=y2=y3=a=b=c=0;
}



}

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry » Fri Aug 08, 2003 9:22 pm

Change:

Code: Select all

while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3)) 
To:

Code: Select all

while(6==scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3)) 
scanf returns -1 for EOF (if I recall correctly), which is non-zero, which makes this loop go forever...

udvat
New poster
Posts: 29
Joined: Thu Aug 07, 2003 9:56 pm

thanxxxxxxxx friend

Post by udvat » Fri Aug 08, 2003 10:05 pm

It was such a silly mistake..................I got AC now,thank u very much :D :D :D

guayoyo
New poster
Posts: 11
Joined: Wed Aug 17, 2005 5:59 pm
Location: Caracas, Venezuela

438 - Precision Error :-?

Post by guayoyo » Fri Aug 19, 2005 4:34 pm

Hi everybody. I think i've got an error with this problem, and I think it's a precision error, because many of my friends have solved it with in the same manner and got AC, but I got WA. If someone want to see the code, here it is:

Code: Select all

#include "ctype.h"
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "stdarg.h"
#include "search.h"
#include "time.h"

#ifndef ONLINE_JUDGE
#define INPUT_NAME "data.in"
//#define OUTPUT_NAME "data.out"
#define DEBUG_NAME "debug.txt"
#endif

//abre la entrada de datos
FILE* openInput() {
#ifndef INPUT_NAME
	return stdin;
#else
	return fopen(INPUT_NAME, "r");
#endif
}

//abre la salida de datos
FILE* openOutput() {
#ifndef OUTPUT_NAME
	return stdout;
#else
	return fopen(OUTPUT_NAME, "w");
#endif
}

// abre el archivo de depuraci
10024 - Guayoyo has Curled Up the Cube!

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

438 - The Circumference of the Circle

Post by helloneo » Sun Sep 11, 2005 1:34 pm

is there any tricky case..?
i don't know why i'm getting WA..

Code: Select all

CUT

line1 and line2 are calculated by given points..
and line3, line4 are evenly and vertically bisecting line1, line2
the intersecting point of line3 and line4 should be the center of the circle..
anything wrong..?
Last edited by helloneo on Fri Jun 08, 2007 6:31 am, edited 2 times in total.

sunny
Experienced poster
Posts: 124
Joined: Sun Sep 11, 2005 10:22 pm
Location: Civil-BUET

Post by sunny » Sun Sep 11, 2005 10:35 pm

u dont need to deal with equation just get the lengths of the line
and area of the triangle. simply put the values
: area = (l1*l2*l3)/(4*radius).

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Mon Sep 12, 2005 4:37 am

i got AC..
thanks.. ^^

shihabrc
New poster
Posts: 49
Joined: Sun Sep 18, 2005 10:20 am
Location: CSE,BUET
Contact:

438 WA HELP!!!!!

Post by shihabrc » Sun Sep 18, 2005 4:15 pm

This program seems OK. It generated correct output for sample input. But i'm getting WA. Please help!! :(
[/code]
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589793

void main(void){
long double k1,k2,x1,y1,x2,y2,x3,y3,rad,cir1,g,f,centx,centy,k;
while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3)==6){
k1=(x3-x1)*(x3-x2)+(y3-y1)*(y3-y2);
k2=(x3-x1)*(y1-y2)+(y3-y1)*(x1-x2);
if(k2){
k=k1/k2;
g=0.5*(k*(y2-y1)-(x1+x2));
f=0.5*(k*(x1-x2)-(y1+y2));
centx=-g;
centy=-f;
rad=sqrt((centx-x1)*(centx-x1)+(centy-y1)*(centy-y1));
cir1=2*rad*PI;
printf("%.2 lf\n", cir1);
}
else printf("0.00\n");
}
}
[/code][/list]

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal » Wed Sep 21, 2005 4:21 pm

The probelm statement did not say that all three points will be distinct. Can your program generate correct output for cases like :

Code: Select all

1.0 1.0 1.0 1.0 1.0 1.0

shihabrc
New poster
Posts: 49
Joined: Sun Sep 18, 2005 10:20 am
Location: CSE,BUET
Contact:

Post by shihabrc » Sat Sep 24, 2005 11:33 am

Yes it works for these inputs. But still giving WA.HELP!!!!!!!!

milacao
New poster
Posts: 5
Joined: Mon Aug 14, 2006 7:57 pm

Post by milacao » Sun Aug 20, 2006 1:23 pm

The probelm statement did not say that all three points will be distinct
You're wrong. The statement says:
You are given the cartesian coordinates of three non-collinear points in the plane.
So if the three points are the same, they are obviously collinear, and they shouldn't be a valid input.

User avatar
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton » Thu Jul 19, 2007 12:51 pm

shihabrc

first try to check the sample input output in the problem carefully. if okey but WA then use forum.
try this
input:

Code: Select all

0.0 0.0 -1.0 7.0 7.0 7.0
output:

Code: Select all

31.42

and also try to print.....

Code: Select all

 "%.2Lf\n"
.

mind that %Lf is for long double, %lf is for double.

hope that helps

RC's
Learning poster
Posts: 65
Joined: Fri Jul 13, 2007 3:17 pm

Post by RC's » Mon Mar 31, 2008 7:21 pm

I got 10 WAs :( :( .. I think this problem is not very difficult.. My program produces same answer as sample input, but i don't know why I got lots of WAs..
Is it because of precision error ? Or anyone else can provide some critical test cases ?

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Re:

Post by emotional blind » Tue Apr 01, 2008 8:21 pm

RC's wrote: Is it because of precision error ?
Not sure, but It could be. What is your value of pi? I defined it as 3.141592653589793

Post Reply

Return to “Volume 4 (400-499)”