Advertisement
edward4324

LABA_YAMP_2_2

Mar 23rd, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.88 KB | None | 0 0
  1. //задача 18
  2.  
  3. #include <iostream>
  4. #include <Windows.h>
  5. #include <string>
  6. #include <vector>
  7. using namespace std;
  8.  
  9. bool
  10. condition_a(const int& N, vector<vector<int>>& T, vector<vector<int>>* unsafe_int);
  11. bool
  12. condition_a(vector<vector<int>>* T);
  13. vector<vector<int>>
  14. condition_B(vector<vector<int>>* T, vector<vector<int>>* unsafe_int, const int EndTime, const int Length);
  15.  
  16. int main() {
  17.  
  18.     SetConsoleCP(1251);
  19.     SetConsoleOutputCP(1251);
  20.  
  21.     vector<vector<int>>* T = new vector<vector<int>>;
  22.     T->resize(2);
  23.  
  24.     int N;
  25.  
  26.     cout << "Введите количество сторожей: ";
  27.     cin >> N;
  28.  
  29.     int input;
  30.  
  31.     for (int i = 0; i < N; i++) {
  32.  
  33.         cout << "Введите интервалы для сторожа №:" << i + 1 << endl;
  34.         cin >> input;
  35.         T->at(0).push_back(input);
  36.         cin >> input;
  37.         T->at(1).push_back(input);
  38.         system("cls");
  39.     }
  40.  
  41.     int Length,
  42.         EndTime;
  43.  
  44.     cout << "Введите продолжительность дежурства дополнительных сторожей: ";
  45.     cin >> Length;
  46.  
  47.     cout << "Введите время окончания дежурства сторожей: ";
  48.     cin >> EndTime;
  49.  
  50.     vector<vector<int>>* uns_periods = new vector<vector<int>>;
  51.     uns_periods->resize(3);
  52.     uns_periods->at(2).push_back(0);
  53.  
  54.     bool proverka = condition_a(N, *T, uns_periods);
  55.  
  56.     if (proverka) {
  57.  
  58.         cout << "Да" << endl;
  59.  
  60.         cout << "Расписание сторожей: " << endl;
  61.  
  62.         for (int i = 0; i < T->at(0).size(); i++) {
  63.  
  64.             cout << "Сторож №" << i + 1 << "\n\tНачало смены: " << T->at(0)[i] << "\tКонец смены: " << T->at(1)[i] << "\t\n";
  65.  
  66.         }
  67.            
  68.  
  69.     }
  70.     else {
  71.  
  72.         cout << "Нет" << endl;
  73.  
  74.         cout << "Информация о проблемных временных промежутках:" << endl;
  75.         Sleep(50);
  76.         system("cls");
  77.         //ПРИ ВЫЗОВЕ ЭТОЙ ФУНКЦИИ НЕ ИЗМЕНЯЕТСЯ Т - ПОФИКСИТЬ
  78.         *T = condition_B(T, uns_periods, EndTime, Length);
  79.  
  80.         cout << "Информация о дополнительных сторожах:";
  81.  
  82.         int k = uns_periods->at(0).size();
  83.        
  84.         for (int i = 0; i < k; i++)
  85.             cout << "\nПромежуток №" << i + 1 << "\tНачало смены: " << T->at(0).at(i + k) << "\tКонец смены: " << T->at(1).at(i + k) << "\n"
  86.             << "\tКоличество сторожей:" << uns_periods->at(2).at(i);
  87.  
  88.  
  89.  
  90.     }
  91.  
  92.     return 0;
  93.  
  94. }
  95.  
  96. bool
  97. condition_a(const int& N, vector<vector<int>>& T, vector<vector<int>>* unsafe_int) {
  98.  
  99.     bool result = false;
  100.     int count = 0;
  101.  
  102.  
  103.     for (int i = 0; i < N; i++) {
  104.  
  105.         for (int j = 0; j < N; j++) {
  106.  
  107.             if (T[0][i] >= T[0][j] && T[1][i] <= T[1][j])
  108.                 //T[0][i] >= T[0][j] && T[1][i] >= T[1][j]
  109.                 count++;
  110.  
  111.         }
  112.  
  113.             if (count >= 2)
  114.                 result = true;
  115.             else {
  116.                
  117.  
  118.                 result = false;
  119.                 unsafe_int->at(0).push_back(T[0][i]);
  120.                 unsafe_int->at(1).push_back(T[1][i]);
  121.                 if
  122.                 (unsafe_int->at(2).at(0) == 0) {
  123.  
  124.                     unsafe_int->at(2).at(0) = (count);
  125.  
  126.                 }
  127.  
  128.                 else
  129.  
  130.                 unsafe_int->at(2).push_back(count);
  131.  
  132.             }
  133.  
  134.        count = 0;
  135.  
  136.     }
  137.  
  138.     return result;
  139.  
  140. }
  141.  
  142. //перегрузка для того, чтобы можно было проверять работу условия в пункте В
  143. bool
  144. condition_a(vector<vector<int>>* T) {
  145.  
  146.     bool result = false;
  147.     int count = 0;
  148.  
  149.  
  150.     for (int i = 0; i < T->at(0).size(); i++) {
  151.  
  152.         for (int j = 0; j < T->at(0).size(); j++) {
  153.  
  154.             if (
  155.  
  156.                 T->at(0).at(i) >= T->at(0).at(j) && T->at(1).at(i) <= T->at(1).at(j)
  157.  
  158.                 )
  159.                 count++;
  160.  
  161.         }
  162.  
  163.         if (count < 2)
  164.             return false;
  165.         else
  166.             result = true;
  167.  
  168.         count = 0;
  169.  
  170.     }
  171.  
  172.     return result;
  173.  
  174. }
  175.  
  176. vector<vector<int>>
  177. condition_B(vector<vector<int>>* T, vector<vector<int>>* unsafe_int, const int EndTime, const int Length) {
  178.  
  179.     vector<vector<int>>* temp = new vector<vector<int>>;
  180.     *temp = *T;
  181.     int i = 0;
  182.     int N = T->size();
  183.  
  184.     while (i < unsafe_int->size()) {
  185.  
  186.         if (!condition_a(temp)) {
  187.  
  188.             //чтобы выполнить пункт в выходных данных нужно ещё добавить вектор,
  189.             /*который будет сохранять промежутки времени у дополнительных сторожей*/
  190.  
  191.             if (unsafe_int->at(0).at(i) + Length <= EndTime) {
  192.  
  193.                 temp->at(0).push_back(unsafe_int->at(0).at(i));
  194.                 temp->at(1).push_back(unsafe_int->at(0).at(i) + Length);
  195.  
  196.             }
  197.             else if ((unsafe_int->at(1).at(i) - Length <= EndTime) && (unsafe_int->at(1).at(i) <= EndTime)) {
  198.  
  199.                 temp->at(0).push_back(unsafe_int->at(1).at(i) - Length);
  200.                 temp->at(1).push_back(unsafe_int->at(1).at(i));
  201.  
  202.             }
  203.         }
  204.  
  205.         i++;
  206.  
  207.     }
  208.  
  209.     return *temp;
  210.  
  211. }
  212.  
  213. vector<vector<int>>*
  214. condiotion_G(const vector<vector<int>>& T, const vector<vector<int>>* unsafe_int, const int EndTime, const int Length) {
  215.  
  216.     vector<vector<int>>* temp = new vector<vector<int>>(T);
  217.  
  218.     int count = T[0].size();
  219.  
  220.     int max_end = T[0][0];
  221.     for (int i = 0; i < T[0].size(); i++)
  222.         if (T[0][i] >= max_end)
  223.             max_end = T[0][i];
  224.  
  225.     for (int i = 0; i < unsafe_int[0].size(); i++)
  226.         count--;
  227.     if (count <= 0)
  228.         return nullptr;
  229.     else if (T[0].size() * Length >= max_end) {
  230.  
  231.  
  232.  
  233.     }
  234.      
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement