Multitasking
Multitasking |
Calendars control our daily lives. For people like me, who are bad at multitasking, it is important to have at most one task planned for any minute of my life. Your job is to make sure that my calendar is free of conflicts for the next one million minutes (just over 99 weeks) of my life. To keep things simple, all times are expressed in minutes from a fixed time 0 representing ``now".
In this calendar, there are two types of tasks: one-time tasks and repeating tasks. One-time tasks have a start time and an end time. Repeating tasks have a start time and an end time for their first occurrence, and a repetition interval. Repeating tasks are assumed to keep repeating forever without end. For example, a repeating task with start time 5, end time 8 and repetition interval 100 would be occurring at time intervals [5..8], [105..108], [205..208], ...
Tasks are considered to be in conflict if and only if their time intervals overlap, for example [2..5] and [4..6] overlap. ``Touching" is OK, for example [2..5] and [5..6] do not overlap.
Input
All numbers are integers in the range [0..1000000]. For each task, the end time is guaranteed to be larger than the start time, and the repetition interval is larger than 0.
Input terminates with a line containing `0 0' which should not be processed.
Output
Sample Input
2 0 10 20 20 30 2 0 10 30 20 21 1 1 1000 2000 0 10 1000 0 0
Sample Output
NO CONFLICT CONFLICT CONFLICT
#include<stdio.h>
#include<string.h>
int z[1000007];
struct sa
{
int start,end,res;
} data[1000007],data1[1000007];
int main()
{
int n,m,i,j,k;
while(scanf("%d%d",&n,&m),n|m)
{
memset(z,0,sizeof(z));
for(i=0; i<n; i++)
{
scanf("%d%d",&data[i].start,&data[i].end);
for(j=data[i].start; j<data[i].end; j++)
z[j]++;
}
for(i=0; i<m; i++)
{
scanf("%d%d%d",&data1[i].start,&data1[i].end,&data1[i].res);
int b=data1[i].start,e=data1[i].end,r=data1[i].res;
while(e<=1000007)
{
for(j=b; j<e; j++)
{
z[j]++;
}
b+=r;
e+=r;
}
}
int flag=0;
for(i=0;i<1000007;i++)
if(z[i]>1)
{
flag=1;
break;
}
if(!flag)printf("NO CONFLICT\n");
else printf("CONFLICT\n");
}
return 0;
}