Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define pi acos(-1)
  5. inline double sqr(double x) {return x*x;}
  6. const int MAX = 300;
  7. const double inf = 0x3f3f3f3f;
  8. int minu[1450];
  9. int pd[1450][721][2][2];
  10. int run(int idx, int paid, int cur, int strt){
  11.     if(idx == 1440){
  12.         if(paid == 720){
  13.             return (cur != strt);
  14.         }
  15.         else return 15000;
  16.     }
  17.     if(paid > 720)return 15000;
  18.     int &res = pd[idx][paid][cur][strt];
  19.     if(res != -1)return res;
  20.     res = 15000;
  21.     if(minu[idx] == 1){
  22.         if(cur)res = min(res, run(idx+1, paid+1, 1, strt));
  23.         else res = min(res, run(idx+1, paid, 1, strt) + 1);
  24.     }else if(minu[idx] == 0){
  25.         if(cur)res = min(res, run(idx+1, paid+1, 0, strt) + 1);
  26.         else res = min(res, run(idx+1, paid, 0, strt));
  27.     }else {
  28.         if(cur){
  29.             res = min(res, min(run(idx+1, paid+1, 1, strt), 1 + run(idx+1, paid+1, 0, strt)));
  30.         }else {
  31.             res = min(res, min(run(idx+1, paid, 0, strt), 1 + run(idx+1, paid, 1, strt)));
  32.         }
  33.     }
  34.     return res;
  35. }
  36. int solve() {
  37.     int n, m, lf, rg, k;
  38.     scanf("%d %d", &n, &m);
  39.     for(int i = 0; i <= 1450; ++i)minu[i] = -1;
  40.     memset(pd, -1, sizeof pd);
  41.     for(int i = 0; i < n+m; ++i){
  42.         scanf("%d %d", &lf, &rg);
  43.         if(i < n)k = 1;
  44.         else k = 0;
  45.         for(int j = lf; j < rg; ++j)minu[j] = k;
  46.     }
  47.     return min(run(0, 0, 0, 0), run(0, 0, 1, 1));
  48. }
  49. int main() {
  50.     int tc;
  51.     scanf("%d", &tc);
  52.     for(int i = 1; i <= tc; ++i)printf("Case #%d: %d\n", i,  solve());
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement