Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool found = false;
- struct ev{
- int s, f, t;
- };
- vector<ev> a;
- int mini(int a, int b, int c, int d){
- if(min(a, b) <= min(c, d)){
- if(a <= b){
- return 0;
- }
- else
- return 1;
- }
- else{
- if(c <= d){
- return 2;
- }
- else{
- return 3;
- }
- }
- }
- void add(int type, int t){
- bool flag = false;
- if(type == 0){
- if(a.size() == 0){
- a.push_back({1, 80, t});
- flag = true;
- }
- else if(a[0].s > 80){
- a.insert(a.begin(), {1, 80, t});
- flag = true;
- }
- else{
- for(int i = 0; i < a.size() - 1; ++i){
- if(a[i + 1].s - a[i].f > 80){
- a.insert(a.begin() + i + 1, {a[i + 1].f + 1, a[i + 1].f + 80, t});
- flag = true;
- break;
- }
- }
- if(!flag){
- if(a.back().f + 80 < 420){
- // cout << 1 << endl;
- a.push_back({a.back().f + 1, a.back().f + 80, t});
- flag = true;
- }
- }
- }
- }
- else{
- if(a.size() == 0){
- a.push_back({1, 40, t});
- flag = true;
- }
- else if(a[0].s > 40){
- a.insert(a.begin(), {1, 40, t});
- flag = true;
- }
- else{
- for(int i = 0; i < a.size() - 1; ++i){
- if(a[i + 1].s - a[i].f > 40){
- a.insert(a.begin() + i + 1, {a[i + 1].f + 1, a[i + 1].f + 40, t});
- flag = true;
- break;
- }
- }
- if(!flag){
- cout << "+" << endl;
- if(a.back().f + 40 < 420){
- a.push_back({a.back().f + 1, a.back().f + 40, t});
- flag = true;
- }
- }
- }
- }
- if(!flag)
- found = true;
- return;
- }
- void del(int type, int t){
- for(int i = 0; i < a.size(); ++i){
- if(a[i].t == t && a[i].f - a[i].s == 80 && !type){
- a.erase(a.begin() + i);
- break;
- }
- if(a[i].t == t && a[i].f - a[i].s == 40 && type){
- a.erase(a.begin() + i);
- break;
- }
- }
- return;
- }
- int main() {
- int c1 = 0;
- int a1 = 0;
- int a2 = 0;
- int d1 = 42;
- int d2 = 21;
- while(!found){
- if(mini(a1, a2, d1, d2) == 2){
- del(0, d1 - 42);
- d1 += 15;
- }
- else if(mini(a1, a2, d1, d2) == 3){
- del(1, d2 - 21);
- d2 += 8;
- }
- else if(mini(a1, a2, d1, d2) == 0){
- c1++;
- add(0, a1);
- a1 += 15;
- }
- else if(mini(a1, a2, d1, d2) == 1){
- add(1, a2);
- a2 += 8;
- }
- for(int i = 0; i < a.size(); ++i){
- cout << a[i].s << " " << a[i].f << " " << a[i].t << endl;
- }
- cout << endl << endl;
- }
- cout << 1 << " " << c1 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement