## 190 - Circle Through Three Points

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 190-Circle Through Three Points

Use the code blocks when posting. Don't put smiley faces in your code.
Print a single blank line after each equation pair.
Check input and AC output for thousands of problems on uDebug!

PromeNabid
New poster
Posts: 21
Joined: Mon Jun 18, 2012 12:52 am
Contact:

### Re: 190-Circle Through Three Points

Getting WA.
1. I followed http://www.regentsprep.org/Regents/math ... 6/RCir.htm this link to find h and k. Then normalized and found r, f, g, c.
2. To aovid division by 0 I first checked if 0 == 0 then it result is 1, if denominator is 0 then result is 0, otherwise did division.
Here is my code.

Code: Select all

``````removed after ac and my idea has been changed a lot.
``````
Update:
To avoid precision read and solve this tutorial of topcoder.
http://community.topcoder.com/tc?module ... =geometry2
Last edited by PromeNabid on Sat Jun 28, 2014 12:26 am, edited 2 times in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 190-Circle Through Three Points

Try the I/O in this thread.
Check input and AC output for thousands of problems on uDebug!

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

### 190 - Circle Through Three Points-- WA

I couldn't understand whats wrong in my code

#include <stdio.h>
#include <math.h>
double slope(double a1, double b1, double a2, double b2)
{
double m;
if(a1 == a2) return 0;
else{
m = ((b2-b1)/(a2-a1));
return m;
}
}
int main()
{
double x1, y1, x2, y2, x3, y3, m1, m2, x, y, r, g, f, c;
int c1;
while(scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3) != EOF){
m1 = slope(x1, y1, x2, y2);
m2 = slope(x2, y2, x3, y3);

x = ((m1 * (y1*m2 - x2 - x3 - y3 * m2) + m2 * (x1 + x2))) / (2 * (m2 - m1));
y = (x1 - x3 + (m1 * (y1 + y2)) - (m2 * (y2 + y3))) / (2 * (m1 - m2));
r = sqrt(((x-x1) * (x -x1)) + ((y-y1) * (y - y1)));

g = - 2 * x;
f = - 2 * y;
c = pow(x, 2) + pow(y, 2) - pow(r, 2);

if(x == -0) x = 0;
if(y == -0) y = 0;
if(g == -0) g = 0;
if(f == -0) f = 0;
if(c == -0) c = 0;

if(x < 0) printf("(x + %.3lf)^2 + ", -x);
else if(x == 0) printf("x^2 + ");
else if(x > 0) printf("(x - %.3lf)^2 + ", x);

if(y < 0) printf("(y + %.3lf)^2 = %.3lf^2\n", -y, r);
else if(y == 0) printf("y^2 = %.3lf^2\n", r);
else if(y > 0) printf("(y - %.3lf)^2 = %.3lf^2\n", y, r);

if(g < 0) printf("x^2 + y^2 - %.3lfx ", -g);
else if(g == 0) printf("x^2 + y^2 ");
else if(g > 0) printf("x^2 + y^2 + %.3lfx ", g);

if(f < 0) printf("- %.3lfy ", -f);
else if(f > 0) printf("+ %.3lfy ", f);

if(c < 0) printf("- %.3lf ", -c);
else if(c > 0) printf("+ %.3lf ", c);
printf("= 0");

printf("\n\n");
}
return 0;
}

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 190 - Circle Through Three Points-- WA

Code: Select all

``Use the code blocks when posting. Like this``
Insert problem number 190 into search box and you will get many explanations why your code may get WA.
http://acm.uva.es/board/search.php?keyw ... fdba2052b1

In that threads you can find input/output to check your program. For example
S.H.Bouwhuis wrote:Here are some sample inputs and outputs for my accepted submission:

Input

Code: Select all

``````7.0 -5.0 -1.0 1.0 0.0 -6.0
1.0 7.0 8.0 6.0 7.0 -2.0
5 5 4 7 16 5
56 40 66 76 31 8
44 39 26 23 37 38
18 82 29 41 33 15
0 49 19 56 98 3
7 0 11 0 9 2
0 9 0 15 3 12
0.0 0.0 1.0 0.0 0.0 2.0
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
0.0 0.0 1.1 0.0 0.0 1.1``````
Output

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 - 10.500)^2 + (y - 9.000)^2 = 6.801^2
x^2 + y^2 - 21.000x - 18.000y + 145.000 = 0

(x + 33.686)^2 + (y - 84.302)^2 = 100.031^2
x^2 + y^2 + 67.372x - 168.603y - 1764.717 = 0

(x - 42.830)^2 + (y - 22.191)^2 = 16.849^2
x^2 + y^2 - 85.660x - 44.383y + 2042.957 = 0

(x + 279.295)^2 + (y + 19.738)^2 = 314.221^2
x^2 + y^2 + 558.590x + 39.475y - 20339.607 = 0

(x - 32.340)^2 + (y + 9.494)^2 = 66.838^2
x^2 + y^2 - 64.679x + 18.987y - 3331.372 = 0

(x - 9.000)^2 + y^2 = 2.000^2
x^2 + y^2 - 18.000x + 77.000 = 0

x^2 + (y - 12.000)^2 = 3.000^2
x^2 + y^2 - 24.000y + 135.000 = 0

(x - 0.500)^2 + (y - 1.000)^2 = 1.118^2
x^2 + y^2 - 1.000x - 2.000y = 0

(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

(x - 0.550)^2 + (y - 0.550)^2 = 0.778^2
x^2 + y^2 - 1.100x - 1.100y = 0
``````
Neto_o wrote:I'm not reading your code since it's not written with the needed spaces and indentation, I can give you some inputs/outputs from my Accepted code, so you can test:

Input:

Code: Select all

``````-34 23 -18 16 20 15
0 0 0 12 12 0
0 12 0 0 12 0
-143 200 -143 -100 200 200
0 0 0.0134 0.0325 0.0888 0.087787
0 0 0.00134 0.00325 0.0888 0.0087787
-42350 -800 0 0 4235 -800

``````
Output:

Code: Select all

``````(x - 2.840)^2 + (y - 85.420)^2 = 72.481^2
x^2 + y^2 - 5.680x - 170.840y + 2051.200 = 0

(x - 6.000)^2 + (y - 6.000)^2 = 8.485^2
x^2 + y^2 - 12.000x - 12.000y + 0.000 = 0

(x - 6.000)^2 + (y - 6.000)^2 = 8.485^2
x^2 + y^2 - 12.000x - 12.000y + 0.000 = 0

(x - 28.500)^2 + (y - 50.000)^2 = 227.843^2
x^2 + y^2 - 57.000x - 100.000y - 48600.000 = 0

(x - 0.116)^2 + (y + 0.029)^2 = 0.120^2
x^2 + y^2 - 0.233x + 0.058y + 0.000 = 0

(x - 0.047)^2 + (y + 0.017)^2 = 0.050^2
x^2 + y^2 - 0.093x + 0.035y + 0.000 = 0

(x + 19057.500)^2 + (y + 112495.156)^2 = 114097.978^2
x^2 + y^2 + 38115.000x + 224990.312y + 0.000 = 0

``````
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

### Re: 190 - Circle Through Three Points-- WA

thanks.

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 190 - Circle Through Three Points-- WA

It will be good if you remove your code after getting accepted. A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman