438  The Circumference of the Circle
Moderator: Board moderators
Q438
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.
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.
438.....why am getting out put limit ex????
#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=(x1x2);
q=(x2x3);
r=(x3x1);
p1=(y1y2);
q1=(y2y3);
r1=(y3y1);
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=(sa);
q=(sb);
r=(sc);
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;
}
}
#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=(x1x2);
q=(x2x3);
r=(x3x1);
p1=(y1y2);
q1=(y2y3);
r1=(y3y1);
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=(sa);
q=(sb);
r=(sc);
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;
}
}

 Guru
 Posts: 647
 Joined: Wed Jun 26, 2002 10:12 pm
 Location: Hong Kong and New York City
 Contact:
Change:
To:
scanf returns 1 for EOF (if I recall correctly), which is nonzero, which makes this loop go forever...
Code: Select all
while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3))
Code: Select all
while(6==scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3))
thanxxxxxxxx friend
It was such a silly mistake..................I got AC now,thank u very much
438  Precision Error :?
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!
438  The Circumference of the Circle
is there any tricky case..?
i don't know why i'm getting WA..
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..?
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.
438 WA HELP!!!!!
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=(x3x1)*(x3x2)+(y3y1)*(y3y2);
k2=(x3x1)*(y1y2)+(y3y1)*(x1x2);
if(k2){
k=k1/k2;
g=0.5*(k*(y2y1)(x1+x2));
f=0.5*(k*(x1x2)(y1+y2));
centx=g;
centy=f;
rad=sqrt((centxx1)*(centxx1)+(centyy1)*(centyy1));
cir1=2*rad*PI;
printf("%.2 lf\n", cir1);
}
else printf("0.00\n");
}
}
[/code][/list]
[/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=(x3x1)*(x3x2)+(y3y1)*(y3y2);
k2=(x3x1)*(y1y2)+(y3y1)*(x1x2);
if(k2){
k=k1/k2;
g=0.5*(k*(y2y1)(x1+x2));
f=0.5*(k*(x1x2)(y1+y2));
centx=g;
centy=f;
rad=sqrt((centxx1)*(centxx1)+(centyy1)*(centyy1));
cir1=2*rad*PI;
printf("%.2 lf\n", cir1);
}
else printf("0.00\n");
}
}
[/code][/list]

 Experienced poster
 Posts: 106
 Joined: Thu Jan 29, 2004 12:07 pm
 Location: Bangladesh
 Contact:
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
 newton
 Experienced poster
 Posts: 162
 Joined: Thu Jul 13, 2006 7:07 am
 Location: Campus Area. Dhaka.Bangladesh
 Contact:
shihabrc
first try to check the sample input output in the problem carefully. if okey but WA then use forum.
try this
input:
output:
and also try to print......
mind that %Lf is for long double, %lf is for double.
hope that helps
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
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
 emotional blind
 A great helper
 Posts: 383
 Joined: Mon Oct 18, 2004 8:25 am
 Location: Bangladesh
 Contact:
Re:
Not sure, but It could be. What is your value of pi? I defined it as 3.141592653589793RC's wrote: Is it because of precision error ?