Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //задача 18
- #include <iostream>
- #include <Windows.h>
- #include <string>
- #include <vector>
- using namespace std;
- bool
- condition_a(const int& N, vector<vector<int>>& T, vector<vector<int>>* unsafe_int);
- bool
- condition_a(vector<vector<int>>* T);
- vector<vector<int>>
- condition_B(vector<vector<int>>* T, vector<vector<int>>* unsafe_int, const int EndTime, const int Length);
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- vector<vector<int>>* T = new vector<vector<int>>;
- T->resize(2);
- int N;
- cout << "Введите количество сторожей: ";
- cin >> N;
- int input;
- for (int i = 0; i < N; i++) {
- cout << "Введите интервалы для сторожа №:" << i + 1 << endl;
- cin >> input;
- T->at(0).push_back(input);
- cin >> input;
- T->at(1).push_back(input);
- system("cls");
- }
- int Length,
- EndTime;
- cout << "Введите продолжительность дежурства дополнительных сторожей: ";
- cin >> Length;
- cout << "Введите время окончания дежурства сторожей: ";
- cin >> EndTime;
- vector<vector<int>>* uns_periods = new vector<vector<int>>;
- uns_periods->resize(3);
- uns_periods->at(2).push_back(0);
- bool proverka = condition_a(N, *T, uns_periods);
- if (proverka) {
- cout << "Да" << endl;
- cout << "Расписание сторожей: " << endl;
- for (int i = 0; i < T->at(0).size(); i++) {
- cout << "Сторож №" << i + 1 << "\n\tНачало смены: " << T->at(0)[i] << "\tКонец смены: " << T->at(1)[i] << "\t\n";
- }
- }
- else {
- cout << "Нет" << endl;
- cout << "Информация о проблемных временных промежутках:" << endl;
- Sleep(50);
- system("cls");
- //ПРИ ВЫЗОВЕ ЭТОЙ ФУНКЦИИ НЕ ИЗМЕНЯЕТСЯ Т - ПОФИКСИТЬ
- *T = condition_B(T, uns_periods, EndTime, Length);
- cout << "Информация о дополнительных сторожах:";
- int k = uns_periods->at(0).size();
- for (int i = 0; i < k; i++)
- cout << "\nПромежуток №" << i + 1 << "\tНачало смены: " << T->at(0).at(i + k) << "\tКонец смены: " << T->at(1).at(i + k) << "\n"
- << "\tКоличество сторожей:" << uns_periods->at(2).at(i);
- }
- return 0;
- }
- bool
- condition_a(const int& N, vector<vector<int>>& T, vector<vector<int>>* unsafe_int) {
- bool result = false;
- int count = 0;
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < N; j++) {
- if (T[0][i] >= T[0][j] && T[1][i] <= T[1][j])
- //T[0][i] >= T[0][j] && T[1][i] >= T[1][j]
- count++;
- }
- if (count >= 2)
- result = true;
- else {
- result = false;
- unsafe_int->at(0).push_back(T[0][i]);
- unsafe_int->at(1).push_back(T[1][i]);
- if
- (unsafe_int->at(2).at(0) == 0) {
- unsafe_int->at(2).at(0) = (count);
- }
- else
- unsafe_int->at(2).push_back(count);
- }
- count = 0;
- }
- return result;
- }
- //перегрузка для того, чтобы можно было проверять работу условия в пункте В
- bool
- condition_a(vector<vector<int>>* T) {
- bool result = false;
- int count = 0;
- for (int i = 0; i < T->at(0).size(); i++) {
- for (int j = 0; j < T->at(0).size(); j++) {
- if (
- T->at(0).at(i) >= T->at(0).at(j) && T->at(1).at(i) <= T->at(1).at(j)
- )
- count++;
- }
- if (count < 2)
- return false;
- else
- result = true;
- count = 0;
- }
- return result;
- }
- vector<vector<int>>
- condition_B(vector<vector<int>>* T, vector<vector<int>>* unsafe_int, const int EndTime, const int Length) {
- vector<vector<int>>* temp = new vector<vector<int>>;
- *temp = *T;
- int i = 0;
- int N = T->size();
- while (i < unsafe_int->size()) {
- if (!condition_a(temp)) {
- //чтобы выполнить пункт в выходных данных нужно ещё добавить вектор,
- /*который будет сохранять промежутки времени у дополнительных сторожей*/
- if (unsafe_int->at(0).at(i) + Length <= EndTime) {
- temp->at(0).push_back(unsafe_int->at(0).at(i));
- temp->at(1).push_back(unsafe_int->at(0).at(i) + Length);
- }
- else if ((unsafe_int->at(1).at(i) - Length <= EndTime) && (unsafe_int->at(1).at(i) <= EndTime)) {
- temp->at(0).push_back(unsafe_int->at(1).at(i) - Length);
- temp->at(1).push_back(unsafe_int->at(1).at(i));
- }
- }
- i++;
- }
- return *temp;
- }
- vector<vector<int>>*
- condiotion_G(const vector<vector<int>>& T, const vector<vector<int>>* unsafe_int, const int EndTime, const int Length) {
- vector<vector<int>>* temp = new vector<vector<int>>(T);
- int count = T[0].size();
- int max_end = T[0][0];
- for (int i = 0; i < T[0].size(); i++)
- if (T[0][i] >= max_end)
- max_end = T[0][i];
- for (int i = 0; i < unsafe_int[0].size(); i++)
- count--;
- if (count <= 0)
- return nullptr;
- else if (T[0].size() * Length >= max_end) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement