Computer Programming Contest Preparation

ToolBox - Source for: 108/10865/judged.c



/home/toolbox/public_html/solutions/108/10865/judged.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_POINTS 200002
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: Sep 10, 2012
   20  * Purpose: Fun
   21  * Problem: 10865 - Brownie Points I
   22  */
   23 
   24 /*
   25  * This template reads data until a terminating value is reached.
   26  */
   27 
   28 struct pointStruct
   29 {
   30     /* define pointStruct */
   31     int x;
   32     int y;
   33 }; /* define pointStruct */
   34 
   35 int cnt;    /* count of points for this case */
   36 int XX;      /* vertical line separating quadrants */
   37 int YY;      /* horizontal line separating quadrants */
   38 struct pointStruct points[MAX_POINTS]; /* array to hold all points */
   39 
   40 void init()
   41 {
   42     /* FUNCTION init */
   43 } /* FUNCTION init */
   44 
   45 void dump()
   46 {
   47     /* FUNCTION dump */
   48 } /* FUNCTION dump */
   49 
   50 int getInput()
   51 {
   52     /* FUNCTION getInput */
   53     int dataReadFlag = FALSE;
   54     int i;
   55 
   56     scanf(" %d ", &cnt);
   57     if (0 != cnt)
   58         {
   59             /* data to process */
   60             dataReadFlag = TRUE;
   61             for (i=0; i<cnt; i++)
   62                 {
   63                     /* read each pair */
   64                     scanf(" %d %d ", &points[i].x, &points[i].y);
   65                 } /* read each pair */
   66             i = cnt / 2;
   67             XX = points[i].x;
   68             YY = points[i].y;
   69         } /* data to process */
   70 
   71     return (dataReadFlag);
   72 } /* FUNCTION getInput */
   73 
   74 void process()
   75 {
   76     /* FUNCTION process */
   77     int stan = 0;    /* quadrants top-right, bottom-left */
   78     int ollie = 0;   /* quadrants top-left, bottom-right */
   79     int i;
   80 
   81     for (i=0; i<cnt; i++)
   82         {
   83             /* process each point (brownie) */
   84             if (XX < points[i].x)
   85                 {
   86                     /* brownie is to right of vertical line */
   87                     if (YY < points[i].y)
   88                         {
   89                             /* point is above horizontal line - quadrant top-right */
   90                             stan++;
   91                         } /* point is above horizontal line - quadrant top-right */
   92                     else if (YY > points[i].y)
   93                         {
   94                             /* point is below horizontal line - quadrant bottom-right */
   95                             ollie++;
   96                         } /* point is below horizontal line - quadrant bottom-right */
   97                 } /* brownie is to right of vertical line */
   98             else if (XX > points[i].x)
   99                 {
  100                     /* brownie is to left of vertical line */
  101                     if (YY < points[i].y)
  102                         {
  103                             /* point is above horizontal line - quadrant top-left */
  104                             ollie++;
  105                         } /* point is above horizontal line - quadrant top-left */
  106                     else if (YY > points[i].y)
  107                         {
  108                             /* point is below horizontal line - quadrant bottom-left */
  109                             stan++;
  110                         } /* point is below horizontal line - quadrant bottom-left */
  111 
  112                 } /* brownie is to left of vertical line */
  113         } /* process each point (brownie) */
  114     printf("%d %d\n", stan, ollie);
  115 } /* FUNCTION process */
  116 
  117 int main ()
  118 {
  119     /* main */
  120     int moreToDo;
  121 
  122     init();
  123     moreToDo = getInput();
  124     while (moreToDo)
  125         {
  126             /* while */
  127             process();
  128             moreToDo = getInput();
  129         } /* while */
  130 
  131     return EXIT_SUCCESS;
  132 } /* main */
  133