Page 5 of 9

Posted: Tue Jan 03, 2006 6:12 pm
by Mohammad Mahmudur Rahman
My AC program gives the follwoing output for your input -

Code: Select all

(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2
x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0

(x - 3.921)^2 + (y - 2.447)^2 = 5.409^2
x^2 + y^2 - 7.842x - 4.895y - 7.895 = 0

(x - 2.500)^2 + (y - 0.000)^2 = 2.500^2
x^2 + y^2 - 5.000x - 0.000y - 0.000 = 0
Note the (y - 0.000) in the 3rd test case.

Re: 190-Circle Through Three points -WA-Already read past po

Posted: Tue Jan 03, 2006 6:20 pm
by tan_Yui
My AC code prints same output as yours.
I think, the bugs of your code is the part of division.
In some parts, your code is in danger of the division by zero.
Parameters; ma, mb, h; are faced with this problem.

Best regards.

Posted: Tue Jan 03, 2006 6:26 pm
by tan_Yui
I think both +0.000 and -0.000 will be accepted.

Still Wa :(

Posted: Tue Jan 03, 2006 6:37 pm
by xintactox
Thanks you for uor reply

I fixed my code to generate answer like ur code do, but still getting WA...

Here's my new code

Code: Select all

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

using namespace std;

class point
{
	public:
		double x, y;
		
};

int main()
{
	point p1, p2, p3;
	double ma, mb, h, k, r, c, d, e;
	while(cin>>p1.x)
	{
		cin>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y;
		ma = (p2.y - p1.y)/(p2.x - p1.x);
		mb = (p3.y - p2.y)/(p3.x - p2.x);
		h = (ma*mb*(p1.y - p3.y) + mb*(p1.x + p2.x) - ma*(p2.x + p3.x))/(2.0*(mb - ma));		
		k = (-1.0/(ma+0.000001))*(h - ((p1.x + p2.x))/2) + (p1.y + p2.y)/2.0;					
		r = sqrt((h - p1.x)*(h - p1.x)+(k - p1.y)*(k - p1.y));
								
		//cout<<"c = "<<c<<endl;
		//cout<<"d = "<<d<<endl;
				
		if(h >= 0.001 || h == 0)
			printf("(x - %.3f)^2 + (y ", fabs(h));
		else
			printf("(x + %.3f)^2 + (y ", fabs((-1)*h));
			
		if(k >= 0.001 || k == 0)
			printf("- %.3f)^2 = %.3f^2", fabs(k), fabs(r));
		else 
			printf("+ %.3f)^2 = %.3f^2", fabs((-1)*k),fabs(r));		
		
		c = 2.0*h;
		d = 2.0*k;
		e = (h*h) + (k*k) - (r*r);
		
		
		if(c >= 0.001 || c == 0)
			printf("\nx^2 + y^2 - %.3fx ", fabs(c));
		else
			printf("\nx^2 + y^2 + %.3fx ", fabs(c));;	
		
		if(d >= 0.001 || d == 0)
			printf("- %.3fy ", fabs(d));
		else
			printf("+ %.3fy ", fabs(d));
		
		if(e > 0.00000001)
			printf("+ %.3f = 0\n", fabs(e));
		else
			printf("- %.3f = 0\n", fabs(e));
		
		printf("\n");		
	}
	return 0;
}
This problem is driving me mad for about three days now... :cry:

Someone help me!

Thanks!

division by zero

Posted: Tue Jan 03, 2006 6:42 pm
by xintactox
Thanks!

Any clue on how avoiding division by zero in this case?
I tried to add very small vlaues in the denominators of the fractions (like 0.000000001 or something) but it changes the output...

Re: division by zero

Posted: Tue Jan 03, 2006 7:00 pm
by tan_Yui
xintactox wrote:Thanks!

Any clue on how avoiding division by zero in this case?
I tried to add very small vlaues in the denominators of the fractions (like 0.000000001 or something) but it changes the output...
Try the following case.
In current your code, if (p2.x - p1.x == 0.000) or (p3.x - p2.x == 0.000) or (mb - ma == 0.000), it'll be occured.

My code tries to separate some cases by the parameters (e.g. when p2.x - p1.x == 0.000, calculate in some function).
, then no need to use tiny values for avoiding precision error.

Code: Select all

 6.6  2.5 -4.0 -4.0  6.6 -8.0
 3.7 -4.1  3.7 -1.5  1.0  1.0
 9.0 -2.0  1.0  1.0 -5.0 -2.0
 5.4  6.3  0.0  6.3 -7.8 -0.8
 3.1  4.1  5.9  2.6  5.3  5.8
10.0 11.0 12.0 13.0  0.0  0.0
My output is :

Code: Select all

(x - 2.526)^2 + (y + 2.750)^2 = 6.645^2
x^2 + y^2 - 5.053x + 5.500y - 30.211 = 0

(x + 0.011)^2 + (y + 2.800)^2 = 3.932^2
x^2 + y^2 + 0.022x + 5.600y - 7.622 = 0

(x - 2.000)^2 + (y + 8.500)^2 = 9.552^2
x^2 + y^2 - 4.000x + 17.000y - 15.000 = 0

(x - 2.700)^2 + (y + 4.501)^2 = 11.133^2
x^2 + y^2 - 5.400x + 9.001y - 96.399 = 0

(x - 4.883)^2 + (y - 4.066)^2 = 1.784^2
x^2 + y^2 - 9.767x - 8.131y + 37.195 = 0

(x - 142.500)^2 + (y + 119.500)^2 = 185.974^2
x^2 + y^2 - 285.000x + 239.000y - 0.000 = 0

Best regards.

Posted: Tue Jan 03, 2006 7:01 pm
by Mohammad Mahmudur Rahman
Try this input -

Code: Select all

0.0 0.0 1.1 0.0 0.0 1.1
output should be -

Code: Select all

(x - 0.550)^2 + (y - 0.550)^2 = 0.778^2
x^2 + y^2 - 1.100x - 1.100y - 0.000 = 0

Posted: Tue Jan 03, 2006 7:03 pm
by Mohammad Mahmudur Rahman
tan_Yui wrote:I think both +0.000 and -0.000 will be accepted.
Note that this program doesn't have a special corrector program. So, how both can get AC? :o However, I modified my code to print +0.000 & that got AC as well. So, apparantly there's no such input.

Posted: Tue Jan 03, 2006 7:11 pm
by tan_Yui
Mohammad Mahmudur Rahman wrote:Note that this program doesn't have a special corrector program. So, how both can get AC? :o However, I modified my code to print +0.000 & that got AC as well. So, apparantly there's no such input.
I checked both case by changing my code like you did, then thought simply both can get AC.
I also believe there's no such input.

Thank you.

presentaion error 190

Posted: Sat Jan 07, 2006 10:41 am
by =viki=
here is my code
plz check why PE

Code: Select all


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

int main(void)
{
	float x[3],y[3];
	float mid1X,mid2X,mid1Y,mid2Y,m1,m2,c1,c2,temp;
	float h,k,r,c,d,e;
	while(scanf("%f%f%f%f%f%f",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2])==6)
	{
/*	while(!feof(in))
	{	for(l=0;l<3;l++)
			fscanf(in,"%f%f",&x[l],&y[l]); */
		mid1X=(x[0]+x[1])/2;
		mid1Y=(y[0]+y[1])/2;
		m1=-(x[0]-x[1])/(y[0]-y[1]);
		mid2X=(x[1]+x[2])/2;
		mid2Y=(y[1]+y[2])/2;
		m2=-(x[1]-x[2])/(y[1]-y[2]);
		c1=mid1Y-(m1*mid1X);
		c2=mid2Y-(m2*mid2X);
		h=(c2-c1)/(m1-m2);
		k=(m1*h)+c1;
		temp=pow((x[0]-h),2)+pow((y[0]-k),2);
		r=sqrt(temp);
		e=pow(h,2)+pow(k,2)-temp;
		d=-2*k;
		c=-2*h;
		if(h<0)
			printf("(x + %.3f)^2 +  ",-h);
		else
			printf("(x - %.3f)^2 + ",h);
		if(k<0)
			printf("(y + %.3f)^2 = ",-k);
		else
			printf("(y - %.3f)^2 = ",k);
		printf("%.3f^2\n",r);
		printf("x^2 + y^2 ");
		if(c<0)
			printf("- %.3fx ",-c);
		else if(c>0)
			printf("+ %.3fx ",c);
		else
			printf("- 0.000x ");
		if(d<0)
			printf("- %.3fy ",-d);
		else if(d>0)
			printf("+ %.3fy ",d);
		else
			printf("- 0.000y ");
		if(e<0)
			printf("- %.3f = 0\n",-e);
		else
			printf("+ %.3f = 0\n",e);
		printf("\n");
	}
	return 0;
}
i gave up looking for any presentation error...
plz help me with this.. where is the error..

Posted: Sat Jan 07, 2006 10:45 am
by =viki=
im getting PE on this code

Code: Select all

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

int main(void)
{
	float x[3],y[3];
	float mid1X,mid2X,mid1Y,mid2Y,m1,m2,c1,c2,temp;
	float h,k,r,c,d,e;
	while(scanf("%f%f%f%f%f%f",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2])==6)
	{
/*	while(!feof(in))
	{	for(l=0;l<3;l++)
			fscanf(in,"%f%f",&x[l],&y[l]); */
		mid1X=(x[0]+x[1])/2;
		mid1Y=(y[0]+y[1])/2;
		m1=-(x[0]-x[1])/(y[0]-y[1]);
		mid2X=(x[1]+x[2])/2;
		mid2Y=(y[1]+y[2])/2;
		m2=-(x[1]-x[2])/(y[1]-y[2]);
		c1=mid1Y-(m1*mid1X);
		c2=mid2Y-(m2*mid2X);
		h=(c2-c1)/(m1-m2);
		k=(m1*h)+c1;
		temp=pow((x[0]-h),2)+pow((y[0]-k),2);
		r=sqrt(temp);
		e=pow(h,2)+pow(k,2)-temp;
		d=-2*k;
		c=-2*h;
		if(h<0)
			printf("(x + %.3f)^2 +  ",-h);
		else
			printf("(x - %.3f)^2 + ",h);
		if(k<0)
			printf("(y + %.3f)^2 = ",-k);
		else
			printf("(y - %.3f)^2 = ",k);
		printf("%.3f^2\n",r);
		printf("x^2 + y^2 ");
		if(c<0)
			printf("- %.3fx ",-c);
		else if(c>0)
			printf("+ %.3fx ",c);
		else
			printf("- 0.000x ");
		if(d<0)
			printf("- %.3fy ",-d);
		else if(d>0)
			printf("+ %.3fy ",d);
		else
			printf("- 0.000y ");
		if(e<0)
			printf("- %.3f = 0\n",-e);
		else
			printf("+ %.3f = 0\n",e);
		printf("\n");
	}
	return 0;
}
im printing -0.000 if theres any...
tried bothe +0.000 nad -0.000 still getting PE....plz help..

Re: presentaion error 190

Posted: Sat Jan 07, 2006 2:56 pm
by tobby
=viki= wrote:

Code: Select all

		if(h<0)
			printf("(x + %.3f)^2 +  ",-h);
		else
			printf("(x - %.3f)^2 + ",h);
The format of this part is incorrect. I wonder why you didn't see this.

Posted: Sat Jan 07, 2006 2:59 pm
by tobby
Please give up the habit of making cross posting. Your question has been answered in another thread.

Thank you! I got PE too!

Posted: Sat Jan 21, 2006 3:35 pm
by Psyco
Thank you Source!

I inserted some parts, and I got AC!!

Posted: Fri Apr 07, 2006 1:43 pm
by sluga
I didn't explicitly take care of printing +0.000 or -0.000, and got P.E.
I solved one problem here on ACM in which you have to judge some outputs. It stated that if al numerals are correct, but some letters are wrong, this is considered P.E. I believe this is the case here.