/home/toolbox/public_html/solutions/119/11926/c.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
66 DEBUG printf("start = %d stop = %d\n", start, stop);
67 /*
68 * if a[start] is a 1 then start conflicts with another sequence
69 * if a[start] is a 2 then start conflicts with start of another swquence
70 * if a[stop] is a 1 then stop is in ,iddle of another sequence
71 * if a[stop] is 3 the stop is at end of another sequence
72 */
73 overlap = overlap || (1 == a[start]) || (2 == a[start]) || (1 == a[stop]) || (3 == a[stop]);
74 a[start] = 2;
75 if (MAX > stop)
76 {
77 /* stop is okay */
78 a[stop] = 3;
79 } /* stop is okay */
80 else
81 {
82 /* reset stop */
83 stop = MAX;
84 } /* reset stop */
85 for (j=start+1; j<stop; j++)
86 {
87 /* for each time between */
88 overlap = overlap || (0 != a[j]);
89 a[j] = 1;
90 } /* for each time between */
91 } /* FUNCTION doTask */
92
93 void process()
94 {
95 /* FUNCTION process */
96 int i;
97 int j;
98 int start;
99 int stop;
100 int interval;
101
102 overlap = FALSE;
103 for (i=0; i<n; i++)
104 {
105 /* process each one time task */
106 scanf(" %d %d ", &start, &stop);
107 doTask(start, stop);
108 } /* process each one time task */
109 for (i=0; i<m; i++)
110 {
111 /* process each repeat task */
112 scanf(" %d %d %d ", &start, &stop, &interval);
113 DEBUG printf("start = %d stop = %d interval = %d\n", start, stop, interval);
114 stop = stop - start;
115 for (j=start; j<MAX; j=j+interval)
116 {
117 /* for each interval */
118 doTask(j, j+stop);
119 } /* for each interval */
120 } /* process each repeat task */
121 if (! overlap)
122 {
123 printf("NO ");
124 }
125 printf("CONFLICT\n");
126 } /* FUNCTION process */
127
128 int main()
129 {
130 /* main */
131 int moreToDo;
132
133 moreToDo = getInput();
134 while (moreToDo)
135 {
136 /* while */
137 init();
138 process();
139 moreToDo = getInput();
140 } /* while */
141
142 return EXIT_SUCCESS;
143 } /* main */
144