Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/119/11926/ao.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+1];
   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     return (dataReadFlag);
   58 } /* FUNCTION getInput */
   59 
   60 void doTask(int start, int stop)
   61 {
   62     /* FUNCTION doTask */
   63     int j;
   64     int tmp;
   65 
   66     tmp = stop;
   67     if (tmp >= MAX)
   68         {
   69             tmp = MAX;
   70         }
   71 
   72     for (j=start; (! overlap) && (j<tmp); j++)
   73         {
   74             /* for each time between */
   75             overlap = overlap || (0 != a[j]);
   76             a[j] = 1;
   77         } /* for each time between */
   78 } /* FUNCTION doTask */
   79 
   80 void process()
   81 {
   82     /* FUNCTION process */
   83     int i;
   84     int j;
   85     int start;
   86     int stop;
   87     int interval;
   88 
   89     overlap = FALSE;
   90     for (i=0; i<n; i++)
   91         {
   92             /* process each one time task */
   93             scanf(" %d %d ", &start, &stop);
   94             doTask(start, stop);
   95         } /* process each one time task */
   96     for (i=0; i<m; i++)
   97         {
   98             /* process each repeat task */
   99             scanf(" %d %d %d ", &start, &stop, &interval);
  100             stop = stop - start;
  101             for (j=start; j<MAX; j=j+interval)
  102                 {
  103                     /* for each interval */
  104                     doTask(j, j+stop);
  105                 } /* for each interval */
  106         } /* process each repeat task */
  107     if (! overlap)
  108         {
  109             printf("NO ");
  110         }
  111     printf("CONFLICT\n");
  112 } /* FUNCTION process */
  113 
  114 int main()
  115 {
  116     /* main */
  117     int moreToDo;
  118 
  119     moreToDo = getInput();
  120     while (moreToDo)
  121         {
  122             /* while */
  123             init();
  124             process();
  125             moreToDo = getInput();
  126         } /* while */
  127 
  128     return EXIT_SUCCESS;
  129 } /* main */
  130