Computer Programming Contest Preparation

ToolBox - Source for: 4/438/a.c



/home/toolbox/public_html/solutions/4/438/a.c
    1 #include <stdio.h>
    2 #include <string.h>
    3 #include <sys/types.h>
    4 #include <sys/stat.h>
    5 #include <fcntl.h>
    6 #include <stdint.h>
    7 #include <math.h>
    8 #include <stdlib.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 #define MAX_LINE 257
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2016-04-25
   20  * Purpose: fun
   21  * Problem: 438 The Circumference of a circle
   22  */
   23 
   24 /*
   25  * This will have to take 3 points, discover the circle
   26  * that intersects all 3 points and then figure out its
   27  * circumference.
   28  *
   29  * I will approach it via the process of taking the points
   30  * (A, B, C) and constructing two lines (AB and BC). Then
   31  * figure out the perpendicular lines that go through the
   32  * middle of these chords, and then see where these lines
   33  * meet -- this will be the center of the circle. Then using
   34  * A, and the center we can calculate the radius. Given the radius,
   35  * we can get the circumference.
   36  */
   37 
   38 struct pointStruct
   39 {
   40     /* STRUCT pointStruct */
   41     double x;
   42     double y;
   43 }; /* STRUCT pointStruct */
   44 
   45 struct pointStruct A;
   46 struct pointStruct B;
   47 struct pointStruct C;
   48 
   49 
   50 
   51 void init()
   52 {
   53     /* FUNCTION init */
   54 } /* FUNCTION init */
   55 
   56 void dump()
   57 {
   58     /* FUNCTION dump */
   59 } /* FUNCTION dump */
   60 
   61 int getInput()
   62 {
   63     /* FUNCTION getInput */
   64     int dataReadFlag;
   65 
   66     dataReadFlag = (6 == scanf(" %lf %lf %lf %lf %lf %lf ", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y));
   67     return (dataReadFlag);
   68 } /* FUNCTION getInput */
   69 
   70 void process()
   71 {
   72     /* FUNCTION process */
   73     int ABhorizontalFlag = FALSE;
   74     int BChorizontalFlag = FALSE;
   75 
   76     /* use AB and BC */
   77     if (A.x == B.x)
   78         {
   79             /* vertical line -- so perpendicular will be horizontal */
   80             mAB = 0;
   81             bAB = (A.y - B.y) / 2 + A.y;
   82         } /* vertical line -- so perpendicular will be horizontal */
   83     else if (A.y == B.y)
   84         {
   85             /* Horizontal line -- so perpendicular will vertical */
   86             ABhorizontalFlag = TRUE;
   87             bAB = (A.x - B.x) / 2 + A.x;
   88         } /* Horizontal line -- so perpendicular will vertical */
   89     else
   90         {
   91             /* regular case -- line is not horizontal nor perpendicular */
   92             mAB = (A.y - B.y) / (A.x - B.x);
   93             bAB = A.y - (A.x * mAB)
   94         } /* regular case -- line is not horizontal nor perpendicular */
   95 
   96 
   97 
   98 } /* FUNCTION process */
   99 
  100 int main()
  101 {
  102     /* main */
  103     int moreToDo;
  104 
  105     init();
  106     moreToDo = getInput();
  107     while (moreToDo)
  108         {
  109             /* while */
  110             process();
  111             moreToDo = getInput();
  112         } /* while */
  113 
  114     return EXIT_SUCCESS;
  115 } /* main */
  116