Introduction

This is my blog of programming, I take notes and leave codes of computer science problems I solved here. Be my guest to comment :)

Friday, December 14, 2012

uva 11926 - Multitasking


/*
Problem link
Type: Adhoc, brute-force
*/
 1  #include <iostream>
 2  #include <cstdio>
 3  #include <cstring>
 4  #include <cmath>
 5  #include <cstdlib>
 6  #include <vector>
 7  using namespace std;
 8  const int maxn = 1000010;
 9  //---------------------------------
10  bool fre[maxn];
11  int n,m,maxlen,cnt;
12  //---------------------------------
13  int main()
14  {
15      int u,v,k;
16      while (true)
17      {
18          memset(fre,true,sizeof(fre));
19          bool conf = false;
20          cin >> n >> m;
21          if (n==0 && m==0) break;
22          for (int i=1; i<=n; i++)
23          {
24              cin >> u >> v;
25              if (!conf)
26              {
27                  for (int j=u+1; j<=v; j++)
28                      if (!fre[j]) { conf = true; break;}
29                      else fre[j] = false;
30              }
31          }
32          for (int i=1; i<=m; i++)
33          {
34              cin >> u >> v >> k;
35              int uu = u;
36              int vv = v;
37              if (!conf)
38                  while (uu<=maxn)
39                  {
40                      for (int j=uu+1; j<=min(vv,maxn); j++)
41                          if (!fre[j]) { conf = true; break;}
42                          else fre[j] =false;
43                      uu += k;
44                      vv += k;
45                  }
46          }
47          if (!conf) cout << "NO CONFLICT" << endl;
48          else cout << "CONFLICT" << endl;
49      }
50      return 0;
51  }

No comments:

Post a Comment