Computer Programming Contest Preparation

ToolBox - Source for: 100/10050/a.c



/home/toolbox/public_html/solutions/100/10050/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_DAYS 3655
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2012-07-18
   20  * Purpose: fun
   21  * Problem: 10050 Hartals
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 int numberOfTimes;
   29 int days;
   30 int parties;
   31 int ary[MAX_DAYS];
   32 
   33 void init()
   34 {
   35     /* FUNCTION init */
   36     scanf("%d ", &numberOfTimes);
   37 } /* FUNCTION init */
   38 
   39 void dump()
   40 {
   41     /* FUNCTION dump */
   42 } /* FUNCTION dump */
   43 
   44 void getInput()
   45 {
   46     /* FUNCTION getInput */
   47     int i;
   48 
   49     scanf(" %d ", &days);
   50     for (i=1; i<= days; i++)
   51         {
   52             /* empty ary */
   53             ary[i] = 0;
   54         } /* empty ary */
   55     scanf(" %d ", &parties);
   56 } /* FUNCTION getInput */
   57 
   58 void process()
   59 {
   60     /* FUNCTION process */
   61     int p;
   62     int hartal;
   63     int h;
   64     int sum = 0;
   65 
   66     for (p=0; p<parties; p++)
   67         {
   68             /* process each party */
   69             scanf(" %d ", &hartal);
   70 
   71             for (h=hartal; h<=days; h=h+hartal)
   72                 {
   73                     /* for */
   74                     ary[h] = 1;
   75                 } /* for */
   76         } /* process each party */
   77 
   78     for (h=6; h<=days; h=h+7)
   79         {
   80             /* blank out holidays -- Friday/Saturday */
   81             ary[h] = 0;
   82             ary[h+1] = 0;
   83         } /* blank out holidays -- Friday/Saturday */
   84 
   85     for (h=1; h<= days; h++)
   86         {
   87             /* count the days off */
   88             sum = sum + ary[h];
   89         } /* count the days off */
   90 
   91     printf("%d\n", sum);
   92 
   93 } /* FUNCTION process */
   94 
   95 int main ()
   96 {
   97     /* main */
   98     int i;
   99 
  100     init();
  101     for (i=0; i<numberOfTimes; i++)
  102         {
  103             /* while */
  104             getInput();
  105             process();
  106         } /* while */
  107 
  108     return EXIT_SUCCESS;
  109 } /* main */
  110 
  111