Advertisement
deushiro

Untitled

Feb 8th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool found = false;
  6.  
  7. struct ev{
  8.     int s, f, t;
  9. };
  10.  
  11.  
  12. vector<ev> a;
  13.  
  14. int mini(int a, int b, int c, int d){
  15.     if(min(a, b) <= min(c, d)){
  16.         if(a <= b){
  17.             return 0;
  18.         }
  19.         else
  20.             return 1;
  21.     }
  22.     else{
  23.         if(c <= d){
  24.             return 2;
  25.         }
  26.         else{
  27.             return 3;
  28.         }
  29.     }
  30. }
  31.  
  32. void add(int type, int t){
  33.     bool flag = false;
  34.     if(type == 0){
  35.         if(a.size() == 0){
  36.             a.push_back({1, 80, t});
  37.             flag = true;
  38.         }
  39.         else if(a[0].s > 80){
  40.             a.insert(a.begin(), {1, 80, t});
  41.             flag = true;
  42.         }
  43.         else{
  44.             for(int i = 0; i < a.size() - 1; ++i){
  45.                 if(a[i + 1].s - a[i].f > 80){
  46.                     a.insert(a.begin() + i + 1, {a[i + 1].f + 1, a[i + 1].f + 80, t});
  47.                     flag = true;
  48.                     break;
  49.                 }
  50.             }
  51.             if(!flag){
  52.                 if(a.back().f + 80 < 420){
  53.                    // cout << 1 << endl;
  54.                     a.push_back({a.back().f + 1, a.back().f + 80, t});
  55.                     flag = true;
  56.                 }
  57.             }
  58.         }
  59.     }
  60.     else{
  61.         if(a.size() == 0){
  62.             a.push_back({1, 40, t});
  63.             flag = true;
  64.         }
  65.         else if(a[0].s > 40){
  66.             a.insert(a.begin(), {1, 40, t});
  67.             flag = true;
  68.         }
  69.         else{
  70.             for(int i = 0; i < a.size() - 1; ++i){
  71.                 if(a[i + 1].s - a[i].f > 40){
  72.                     a.insert(a.begin() + i + 1, {a[i + 1].f + 1, a[i + 1].f + 40, t});
  73.                     flag = true;
  74.                     break;
  75.                 }
  76.             }
  77.             if(!flag){
  78.                 cout << "+" << endl;
  79.                 if(a.back().f + 40 < 420){
  80.                     a.push_back({a.back().f + 1, a.back().f + 40, t});
  81.                     flag = true;
  82.                 }
  83.             }
  84.         }
  85.     }
  86.     if(!flag)
  87.         found = true;
  88.     return;
  89. }
  90. void del(int type, int t){
  91.     for(int i = 0; i < a.size(); ++i){
  92.         if(a[i].t == t && a[i].f - a[i].s == 80 && !type){
  93.             a.erase(a.begin() + i);
  94.             break;
  95.         }
  96.          if(a[i].t == t && a[i].f - a[i].s == 40 && type){
  97.             a.erase(a.begin() + i);
  98.             break;
  99.         }
  100.     }
  101.     return;
  102. }
  103.  
  104.  
  105. int main() {
  106.     int c1 = 0;
  107.     int a1 = 0;
  108.     int a2 = 0;
  109.     int d1 = 42;
  110.     int d2 = 21;
  111.     while(!found){
  112.         if(mini(a1, a2, d1, d2) == 2){
  113.             del(0, d1 - 42);
  114.             d1 += 15;
  115.         }
  116.         else if(mini(a1, a2, d1, d2) == 3){
  117.             del(1, d2 - 21);
  118.             d2 += 8;
  119.         }
  120.         else if(mini(a1, a2, d1, d2) == 0){
  121.             c1++;
  122.             add(0, a1);
  123.             a1 += 15;
  124.         }
  125.         else if(mini(a1, a2, d1, d2) == 1){
  126.             add(1, a2);
  127.             a2 += 8;
  128.         }
  129.         for(int i = 0; i < a.size(); ++i){
  130.             cout << a[i].s << " " << a[i].f << " " << a[i].t << endl;
  131.         }
  132.         cout << endl << endl;
  133.     }
  134.     cout << 1 << " " << c1 << endl;
  135.    
  136.    
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement