Computer Programming Contest Preparation

ToolBox - Source for: 102/10245/a.c



/home/toolbox/public_html/solutions/102/10245/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 MAXPOINTS 10005
   16 #define MAXINT 0x7FFFFFFF
   17 
   18 
   19 int numPoints;
   20 int x[MAXPOINTS];
   21 int y[MAXPOINTS];
   22 int dist[MAXPOINTS][MAXPOINTS];
   23 
   24 /*
   25  *  Author:
   26  *    Date:
   27  * Purpose:
   28  * Problem:
   29  */
   30 
   31 /*
   32  * This template reads data until a terminating value is reached.
   33  */
   34 
   35 void init()
   36 {
   37     /* FUNCTION init */
   38     int i;
   39     int j;
   40 
   41     for (i=0; i<numPoints; i++)
   42         {
   43             /* for i */
   44             for (j=0; j<numPoints; j++)
   45                 {
   46                     /* for j */
   47                     dist[i][j] = 0;
   48                 } /* for j */
   49         } /* for i */
   50 } /* FUNCTION init */
   51 
   52 void dump()
   53 {
   54     /* FUNCTION dump */
   55     int i;
   56 
   57     printf("dump\n");
   58     printf("NumPoints=%d\n", numPoints);
   59     for (i=0; i<numPoints; i++)
   60         {
   61             /* for */
   62             printf("x[%d] = %d  y[%d] = %d\n", i, x[i], i, y[i]);
   63         } /* for */
   64 } /* FUNCTION dump */
   65 
   66 void dumpDist()
   67 {
   68     /* FUNCTION dumpDist */
   69     int i;
   70     int j;
   71 
   72     printf("dumpDist\n");
   73     printf("NumPoints=%d\n", numPoints);
   74     for (i=0; i<numPoints; i++)
   75         {
   76             /* for */
   77             for (j=0; j<numPoints; j++)
   78                 printf("%9d ", dist[i][j]);
   79             printf("\n");
   80         } /* for */
   81 } /* FUNCTION dumpDist */
   82 
   83 int getInput()
   84 {
   85     /* FUNCTION getInput */
   86     int dataReadFlag;
   87     int i;
   88 
   89     dataReadFlag = FALSE;
   90     scanf("%d ", &numPoints);
   91     if (0 < numPoints)
   92         {
   93             /* then */
   94             dataReadFlag = TRUE;
   95             for (i=0; i<numPoints; i++)
   96                 {
   97                     /* for */
   98                     scanf("%d %d ", &x[i], &y[i]);
   99                 } /* for */
  100         } /* then */
  101 
  102     return (dataReadFlag);
  103 } /* FUNCTION getInput */
  104 
  105 void process()
  106 {
  107     /* FUNCTION process */
  108     int i;
  109     int j;
  110     int xt, yt;
  111     int min = MAXINT;
  112     double d;
  113 
  114     DEBUG dump();
  115 
  116     if (1 < numPoints)
  117         {
  118             /* have at least two points */
  119             init();
  120 
  121             for (i=0; i<numPoints;  i++)
  122                 {
  123                     /* for i */
  124                     for (j=i+1; j<numPoints;  j++)
  125                         {
  126                             /* for j */
  127                             xt = x[i] - x[j];
  128                             yt = y[i] - y[j];
  129                             dist[i][j] = xt * xt + yt * yt;
  130                             if (min > dist[i][j])
  131                                 {
  132                                     /* then */
  133                                     min = dist[i][j];
  134                                 } /* then */
  135                         } /* for j */
  136                 } /* for i */
  137             DEBUG dumpDist();
  138             DEBUG d = min;
  139             DEBUG d = sqrt(d);
  140             DEBUG printf("min = %d %.4lf\n", min, d);
  141             if (100000000 < min)
  142                 {
  143                     /* then */
  144                     printf("Infinity\n");
  145                 } /* then */
  146             else
  147                 {
  148                     /* else */
  149                     printf("%.4lf\n", sqrt( (double) min ));
  150                 } /* else */
  151         } /* have at least two points */
  152     else
  153         printf("Infinity\n");
  154 } /* FUNCTION process */
  155 
  156 int main ()
  157 {
  158     /* main */
  159     int moreToDo;
  160 
  161     init();
  162     moreToDo = getInput();
  163     while (moreToDo)
  164         {
  165             /* while */
  166             process();
  167             moreToDo = getInput();
  168         } /* while */
  169 
  170     return EXIT_SUCCESS;
  171 } /* main */
  172 
  173 
  174