Computer Programming Contest Preparation

ToolBox - Source for: 119/11926/ad.c



/home/toolbox/public_html/solutions/119/11926/ad.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: 2016-8-24
   18  * Purpose: fun
   19  * Problem: 11926 Multitasking
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define MAX 1000001
   27 int a[MAX*2];
   28 
   29 int m;
   30 int n;
   31 int overlap;
   32 
   33 void init()
   34 {
   35     /* FUNCTION init */
   36     int i;
   37 
   38     for (i=0; i<MAX; i++)
   39         {
   40             /* for i */
   41             a[i] = 0;
   42         } /* for i */
   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;
   54 
   55     scanf(" %d %d ", &n, &m);
   56     dataReadFlag = ((0 != m) || (0 != n));
   57     DEBUG printf("n = %d  m = %d   dataReadFlag = %d\n", n, m, dataReadFlag);
   58     return (dataReadFlag);
   59 } /* FUNCTION getInput */
   60 
   61 void doTask(int start, int stop)
   62 {
   63     /* FUNCTION doTask */
   64     int j;
   65     int tmp;
   66 
   67     tmp = stop;
   68     if (tmp >= MAX)
   69         {
   70             tmp = MAX;
   71         }
   72     DEBUG printf("dotask: strat = %d    stop = %d\n", start, stop);
   73     for (j=start; j<tmp; j++)
   74         {
   75             /* for each time between */
   76             DEBUG printf("a[%d] = %d\n", j, a[j]);
   77             overlap = overlap || (0 != a[j]);
   78             a[j] = 1;
   79         } /* for each time between */
   80 } /* FUNCTION doTask */
   81 
   82 void process()
   83 {
   84     /* FUNCTION process */
   85     int i;
   86     int j;
   87     int k;
   88     int start;
   89     int stop;
   90     int interval;
   91 
   92     overlap = FALSE;
   93     for (i=0; i<n; i++)
   94         {
   95             /* process each one time task */
   96             scanf(" %d %d ", &start, &stop);
   97             for (k=999997; k<MAX; k++)
   98                 {
   99                     DEBUG printf("a[%d] = %d\n", k, a[k]);
  100                 }
  101             doTask(start, stop);
  102             for (k=999997; k<MAX; k++)
  103                 {
  104                     DEBUG printf("a[%d] = %d\n", k, a[k]);
  105                 }
  106         } /* process each one time task */
  107     for (i=0; i<m; i++)
  108         {
  109             /* process each repeat task */
  110             scanf(" %d %d %d ", &start, &stop, &interval);
  111             DEBUG printf("start = %d  stop = %d  interval = %d\n", start, stop, interval);
  112             stop = stop - start;
  113             for (j=start; j<MAX; j=j+interval)
  114                 {
  115                     /* for each interval */
  116                     DEBUG printf("process loop: start = %d    stop = %d\n", j, j+stop);
  117                     for (k=999997; k<MAX; k++)
  118                         {
  119                             DEBUG printf("a[%d] = %d\n", k, a[k]);
  120                         }
  121                     doTask(j, j+stop);
  122                     for (k=999997; k<MAX; k++)
  123                         {
  124                             DEBUG printf("a[%d] = %d\n", k, a[k]);
  125                         }
  126                 } /* for each interval */
  127         } /* process each repeat task */
  128     if (! overlap)
  129         {
  130             printf("NO ");
  131         }
  132     printf("CONFLICT\n");
  133 } /* FUNCTION process */
  134 
  135 int main()
  136 {
  137     /* main */
  138     int moreToDo;
  139 
  140     moreToDo = getInput();
  141     while (moreToDo)
  142         {
  143             /* while */
  144             init();
  145             process();
  146             moreToDo = getInput();
  147         } /* while */
  148 
  149     return EXIT_SUCCESS;
  150 } /* main */
  151