Computer Programming Contest Preparation

ToolBox - Source for: 115/11559/a.c



/home/toolbox/public_html/solutions/115/11559/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 /*
   16  *  Author: Isaac Traxler
   17  *    Date:
   18  * Purpose: fun
   19  * Problem:
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 int n;
   27 int b;
   28 int h;
   29 int w;
   30 int best;
   31 
   32 void init()
   33 {
   34     /* FUNCTION init */
   35 } /* FUNCTION init */
   36 
   37 void dump()
   38 {
   39     /* FUNCTION dump */
   40 } /* FUNCTION dump */
   41 
   42 int getInput()
   43 {
   44     /* FUNCTION getInput */
   45     int dataReadFlag;
   46     int i;
   47     int j;
   48     int prc;
   49     int beds;
   50     int mx;
   51     int tmp;
   52 
   53     /* n - people, b - budget, h - num hotels, w - num weeks */
   54     dataReadFlag = 0 < scanf(" %d %d %d %d ", &n, &b, &h, &w);
   55     if (dataReadFlag)
   56         {
   57             /* process hotels */
   58             best = b + 1;
   59             for (i=0; i<h; i++)
   60                 {
   61                     /* process each hotel */
   62                     scanf(" %d ", &prc);
   63                     mx = 0;
   64                     for (j=0; j<w; j++)
   65                         {
   66                             /* read in number of beds */
   67                             scanf(" %d ", &beds);
   68                             mx = beds > mx ? beds : mx;
   69                         } /* process each hotel */
   70                     tmp = prc * n;
   71                     if ((b >= tmp) && (mx >= n))
   72                         {
   73                             /* found an answer */
   74                             best = best < tmp ? best : tmp;
   75                         } /* found an answer */
   76                 } /* read in number of beds */
   77         } /* process hotels */
   78     return (dataReadFlag);
   79 } /* FUNCTION getInput */
   80 
   81 void process()
   82 {
   83     /* FUNCTION process */
   84     if (b>= best)
   85         {
   86             printf("%d\n", best);
   87         }
   88     else
   89         {
   90             printf("stay home\n");
   91         }
   92 } /* FUNCTION process */
   93 
   94 int main()
   95 {
   96     /* main */
   97     int moreToDo;
   98 
   99     init();
  100     moreToDo = getInput();
  101     while (moreToDo)
  102         {
  103             /* while */
  104             process();
  105             moreToDo = getInput();
  106         } /* while */
  107 
  108     return EXIT_SUCCESS;
  109 } /* main */
  110