diff --git a/lab2.cpp b/lab2.cpp new file mode 100644 index 00000000..d80f1b57 --- /dev/null +++ b/lab2.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include + +bool are_isomorph(std::string* line_1, std::string* line_2, std::unordered_map* saved_letters) { // 8 + 4 * 2 = 12 () + int length1 = (*line_1).size(); // 4 + int length2 = (*line_2).size(); // 4 + if (length2 != length1) { return false; } + for (int i = 0; i < length1; i++) { // 24 + 2 * K (max K = 94, K - ) 24 + 80 K <= 40 + auto search = (*saved_letters).find((*line_1)[i]); // 24 + if (search != (*saved_letters).end()) { + if (search->second != (*line_2)[i]) { + return false; + } + } + else { + (*saved_letters).insert({ (*line_1)[i], (*line_2)[i] }); + } + } + return true; +} +//int main(){ +// std::string line_1,line_2; // 80 +// std::cin >> line_1 >> line_2; // N + M (max N, M = 10000, N, M - ) 80 N M <= 40 +// std::unordered_map saved_letters; // 80 +// std::cout << are_isomorph(&line_1, &line_2, &saved_letters) << std::endl; +//} + +// : max(M+N, 80) + 16 + 4 + 4 + max(2*K, 80) + 24 = max(M+N, 80) + max(2*K, 80) + 44 + + +// +void TEST_1() { + std::string line_1{ "foo" }, line_2{ "dff" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 1); + +} + +// +void TEST_2() { + std::string line_1{ "foo" }, line_2{ "dfd" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 0); + +} + +// (a > b) +void TEST_3() { + std::string line_1{ "food" }, line_2{ "dff" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 0); + +} + +// (a < b) +void TEST_4() { + std::string line_1{ "foo" }, line_2{ "dfff" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 0); + +} + +// +void TEST_5() { + std::string line_1{ "" }, line_2{ "" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 1); + +} + +// , + +void TEST_6() { + std::string line_1{ "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890" }; + std::string line_2{ "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 1); + +} + +// , +void TEST_7() { + std::string line_1{ "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890" }; + std::string line_2{ "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjkldfcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 0); + +} + +int main() { + TEST_1(); + TEST_2(); + TEST_3(); + TEST_4(); + TEST_5(); + TEST_6(); + TEST_7(); + std::cout << "All tests completed successfully" << std::endl; +} \ No newline at end of file diff --git a/lab2_fixed.cpp b/lab2_fixed.cpp new file mode 100644 index 00000000..eb6a733b --- /dev/null +++ b/lab2_fixed.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include + +bool are_isomorph(std::string& line_1, std::string& line_2, std::unordered_map& letters_bijection) { + + short int length1 = line_1.length(); // 2 байта + short int length2 = line_2.length(); // 2 байта + if (length2 != length1) { return false; } + + // Сравниваем длину строк, иначе, если строки имеют разную длину, программа либо выдаёт ошибку (length1 > length2), + // либо не проходит вторую строку полностью (length1 < length2) + + for (int i = 0; i < length1; i++) { // 24 + 2 * K байт (max K = 94, где K - количество уникальных символов в строке) или 24 + 80 байт при K <= 40 + + auto search = letters_bijection.find(line_1[i]); // 24 байта + + // unordered_map letters хранит пары вида key = line_1[i], value = line_2[i] + // В каждой итерации цикла проверяем, есть ли элемент line_1[i] в качестве ключа + // в letters или нет. Если нет - создаём ключ line_1[i] со значением line_2[i], + // есть - сравниваем значение с line_2[i]. При несовпадении, возвращаем false, т.к. биекция будет нарушена + if (search != letters_bijection.end()) { + if (search->second != line_2[i]) { + return false; + } + } + else { + letters_bijection.insert({ line_1[i], line_2[i] }); + } + } + + return true; +} +// итоговые затраты памяти (самой функцией): 2 + 2 + max(2*K, 80) + 24 = max(2*K, 80) + 28 байт +// итоговые затраты памяти в целом: max(N,80) + max(M, 80) + 2 + 2 + max(2*K, 80) + 24 = max(N,80) + max(M, 80) + max(2*K, 80) + 28 байт (Где N и M - длины строк) + +int main() { + // Тест из примера + std::string line_11{ "foo" }, line_21{ "dff" }; + std::unordered_map letters_bijection1; + assert(are_isomorph(line_11, line_21, letters_bijection1) == 1); + + // Тест с неизоморфными строками + std::string line_12{ "foo" }, line_22{ "dfd" }; + std::unordered_map letters_bijection2; + assert(are_isomorph(line_12, line_22, letters_bijection2) == 0); + + // Тест со строками разной длины (a > b) + std::string line_13{ "food" }, line_23{ "dff" }; + std::unordered_map letters_bijection3; + assert(are_isomorph(line_13, line_23, letters_bijection3) == 0); + + // Тест со строками разной длины (a < b) + std::string line_14{ "foo" }, line_24{ "dfff" }; + std::unordered_map letters_bijection4; + assert(are_isomorph(line_14, line_24, letters_bijection4) == 0); + + // Тест с пустыми строками + std::string line_15{ "" }, line_25{ "" }; + std::unordered_map letters_bijection5; + assert(are_isomorph(line_15, line_25, letters_bijection5) == 1); + + // Тест с изоморфными строками, содержащими все допустимые символы + std::string line_16{ "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбю" }; + std::string line_26{ "юqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьб" }; + std::unordered_map letters_bijection6; + assert(are_isomorph(line_16, line_26, letters_bijection6) == 1); + + // Тест с неизоморфными строками, содержащими все допустимые символы + std::string line_17{ "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбю" }; + std::string line_27{ "юqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjkldfcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьб" }; + std::unordered_map letters_bijection7; + assert(are_isomorph(line_17, line_27, letters_bijection7) == 0); + + std::cout << "All tests completed successfully" << std::endl; +} \ No newline at end of file diff --git a/lab2fixed.cpp b/lab2fixed.cpp new file mode 100644 index 00000000..e0da0b39 --- /dev/null +++ b/lab2fixed.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include + +bool are_isomorph(std::string* line_1, std::string* line_2, std::unordered_map* saved_letters) { // 8 + 4 * 2 = 12 байт (указатели) + int length1 = (*line_1).size(); // 4 байта + int length2 = (*line_2).size(); // 4 байта + if (length2 != length1) { return false; } + for (int i = 0; i < length1; i++) { // 24 + 2 * K байт (max K = 94, где K - количество уникальных символов в строке) или 24 + 80 байт при K <= 40 + auto search = (*saved_letters).find((*line_1)[i]); // те самые 24 байта + if (search != (*saved_letters).end()) { + if (search->second != (*line_2)[i]) { + return false; + } + } + else { + (*saved_letters).insert({ (*line_1)[i], (*line_2)[i] }); + } + } + return true; +} +//int main(){ +// std::string line_1,line_2; // 80 байт +// std::cin >> line_1 >> line_2; // N + M байт (max N, M = 10000, где N, M - количество символов в строках) или 80 байт при N и M <= 40 +// std::unordered_map saved_letters; // 80 байт +// std::cout << are_isomorph(&line_1, &line_2, &saved_letters) << std::endl; +//} + +// итоговые затраты памяти: max(M+N, 80) + 16 + 4 + 4 + max(2*K, 80) + 24 = max(M+N, 80) + max(2*K, 80) + 44 байт + + +// Тест из примера +void TEST_1() { + std::string line_1{ "foo" }, line_2{ "dff" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 1); + +} + +// Тест с неизоморфными строками +void TEST_2() { + std::string line_1{ "foo" }, line_2{ "dfd" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 0); + +} + +// Тест со строками разной длины (a > b) +void TEST_3() { + std::string line_1{ "food" }, line_2{ "dff" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 0); + +} + +// Тест со строками разной длины (a < b) +void TEST_4() { + std::string line_1{ "foo" }, line_2{ "dfff" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 0); + +} + +// Тест с пустыми строками +void TEST_5() { + std::string line_1{ "" }, line_2{ "" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 1); + +} + +// Тест с изоморфными строками, содержащими все допустимые символы + +void TEST_6() { + std::string line_1{ "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбю" }; + std::string line_2{ "юqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьб" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 1); + +} + +// Тест с неизоморфными строками, содержащими все допустимые символы +void TEST_7() { + std::string line_1{ "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбю" }; + std::string line_2{ "юqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjkldfcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890йцукенгшщзхъфывапролджэячсмитьб" }; + std::unordered_map saved_letters; + assert(are_isomorph(&line_1, &line_2, &saved_letters) == 0); + +} + +int main() { + TEST_1(); + TEST_2(); + TEST_3(); + TEST_4(); + TEST_5(); + TEST_6(); + TEST_7(); + std::cout << "All tests completed successfully" << std::endl; +} \ No newline at end of file diff --git a/lab3_finished.cpp b/lab3_finished.cpp new file mode 100644 index 00000000..51055084 --- /dev/null +++ b/lab3_finished.cpp @@ -0,0 +1,75 @@ +// , Medium +#include +#include +#include + +std::string compression(const std::string text) { + + // : + // = + // N - , K - + + std::string compressed_text; // O(1), 40 + short int count{ 0 }; // O(1), 2 + char left_symbol{ text[0] }; // O(1), 1 + short int text_length = text.length(); // O(1), 2 ( O(1) 10000 , 2^15-1) + compressed_text.reserve(2 * text_length); // O(1) + + for (short int i = 1; i <= text_length; i++) { // O(N); O(K), max(40, 1+log(_1) + ... + 1+log(_K)) + + count++; // O(1) + + if (text[i] != left_symbol) { // O(1) + compressed_text.push_back(left_symbol); // O(1) + if (count != 1) { + compressed_text += std::to_string(count); // O(1+1) O(M + log(count)) , M - , log(count) - count. + } + left_symbol = text[i]; // O(1) + count = 0; // O(1) + + } + } + + return compressed_text; + +} +// ( ): max(40, 1+log(_1) + ... + 1+log(_K)) + 2 + 1 + 2 = max(40, 1+log(_1) + ... + 1+log(_K)) + 5 +// : max(40, 1+log(_1) + ... + 1+log(_K)) + 2 + 1 + 2 + max(40, N) = max(40, 1+log(_1) + ... + 1+log(_K)) + max(40, N) + 5 +// O(N), - O(K) + +int main() { + std::string test_str; + std::string expected; + + // 1 + test_str = "aaabb"; + expected = "a3b2"; + assert(compression(test_str) == expected); + + // 2 + test_str = "wwwwtttttssssshhhhhhhhhh"; + expected = "w4t5s5h10"; + assert(compression(test_str) == expected); + + // 3 + test_str = "qwwwwghtttttsssssfhhhhhhq"; + expected = "qw4ght5s5fh6q"; + assert(compression(test_str) == expected); + + // 4 + test_str = "qwertyuiopasdf"; + expected = "qwertyuiopasdf"; + assert(compression(test_str) == expected); + + // 5 + test_str = ""; + expected = ""; + assert(compression(test_str) == expected); + + // 6 9 + test_str = "qqqqqqqqqqqyuuuuiiiiiiiiiiiiii"; + expected = "q11yu4i14"; + assert(compression(test_str) == expected); + + std::cout << "All tests completed successfully" << std::endl; +} \ No newline at end of file diff --git a/lab4.cpp b/lab4.cpp new file mode 100644 index 00000000..2f681b95 --- /dev/null +++ b/lab4.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include + +std::vector> permut(std::vector& data) { + std::vector> res; + res.reserve(1275); + short int datasize = data.size(); + for (short int i1 = 0; i1 < datasize; i1++){ + for (short int i2 = 0; i2 < datasize; i2++){ + for (short int i3 = 0; i3 < datasize; i3++){ + for (short int i4 = 0; i4 < datasize; i4++){ + for (short int i5 = 0; i5 < datasize; i5++){ + for (short int i6 = i5 + 1; i6 < datasize; i6++){ + for (short int i7 = i6 + 1; i7 < datasize; i7++){ + for (short int i8 = i7+1; i8 < datasize; i8++){ + for (short int i9 = i8+1; i9 < datasize; i9++){ + + if ((data[i1] + data[i2] + data[i3] + data[i4] + data[i5] + data[i6] + data[i7] + data[i8] + data[i9] == 0) && + (i9 > i8) && (i8 > i7) && (i7 > i6) && (i6 > i5) && (i5 > i4) && (i4 > i3) && (i3 > i2) && (i2 > i1)) { + std::cout << '[' << i1 << ' ' << i2 << ' ' << i3 << ' ' << i4 << ' ' << i5 << ' ' << i6 << ' ' << i7 << ' ' << i8 << ' ' << i9 << ']' << std::endl; + res.push_back({ i1 , i2 , i3 , i4 , i5 , i6 , i7 , i8 ,i9 }); + } + }}}}}}}}} + return res; +} + +void test1() { + std::vector r = { 234, -221, 34, -43, -543, 123, 345, -12, 53, 634, -77, 11, 4, 6, -77, 9, 0 }; + assert(permut(r).size() > 1); + std::cout << "Test with more than one combination: Successeful!" << std::endl; +} + + +void test2() { + std::vector r = { 1, -1, 1, -1, 1 , -1, 1, -1, 0 }; + assert(permut(r).size() == 1); + std::cout << "Test with one possible combination: Successeful!" << std::endl; +} + +void test3() { + std::vector r = { 1, 3, 4, 5, 6, 7, 8, 8, 9, 3, 2, 8, 3 }; + assert(permut(r).size() == 0); + std::cout << "Test with zero possible combination: Successeful!" << std::endl; +} + + +int main() { + //test1(); + //test2(); + //test3(); + + //std::vector r = { 0 }; + std::vector r = { 234, -221, 34, -43, -543, 123, 345, -12, 53 }; + //std::vector r = { 234, -221, 34, -43, -543, 123, 345, -12, 53, 634, -77, 11 }; + //std::vector r = { 234, -221, 34, -43, -543, 123, 345, -12, 53, 634, -77, 11, 4, 6, -77 }; + //std::vector r = { 234, -221, 34, -43, -543, 123, 345, -12, 53, 634, -77, 11, 4, 6, -77, 9, 0, 55}; + //std::vector r = { 234, -221, 34, -43, -543, 123, 345, -12, 53, 634, -77, 11, 4, 6, -77, 9, 0, 55, -1, -5, -41 }; + //std::vector r = { 234, -221, 34, -43, -543, 123, 345, -12, 53, 634, -77, 11, 4, 6, -77, 9, 0, 55, -1, -5, -41, 65, -4, 90, 236 }; + auto begin = std::chrono::steady_clock::now(); + std::cout << permut(r).size() << std::endl; + auto end = std::chrono::steady_clock::now(); + auto elapsed_ms = std::chrono::duration_cast(end - begin); + std::cout << "The time: " << elapsed_ms.count() << " ms\n"; + + + return 0; +} \ No newline at end of file diff --git a/lab5.cpp b/lab5.cpp new file mode 100644 index 00000000..46c2b962 --- /dev/null +++ b/lab5.cpp @@ -0,0 +1,201 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +void generator(std::vector& a, int n) { + for (int i = 0; i < n; i++) { + a[i] = static_cast(std::rand()); + } +} + +void bubbleSort(std::vector& a, int n) { // 8+4 = 12 + for (int i = 0; i < n - 1; i++) { // 4 + for (int j = 0; j < n - i - 1; j++) { // 4 + if (a[j] > a[j + 1]) + std::swap(a[j], a[j + 1]); + } + } +} + +int part(std::vector& a, int left, int right) { // 8+4+4=16 + int pivot = a[right]; // 4 + int i = left - 1; // 4 + for (int j = left; j <= right - 1; j++) { // 4 + if (a[j] < pivot) { + i++; + std::swap(a[i], a[j]); + } + } + std::swap(a[i + 1], a[right]); + return i + 1; +} + +void quick_sort(std::vector& a, int left, int right) { // 8+4+4=16 + if (left < right) { + int pi = part(a, left, right); // 4 + quick_sort(a, left, pi - 1); + quick_sort(a, pi + 1, right); + } +} + +int getMin(std::vector& a, int n) // 8+4 = 12 +{ + int res = a[0]; // 4 + for (int i = 1; i < n; i++) // 4 + res = std::min(res, a[i]); + return res; +} + +int getMax(std::vector& a, int n) +{ + int res = a[0]; + for (int i = 1; i < n; i++) + res = std::max(res, a[i]); + return res; +} + +void pigeonhole_sort(std::vector& a, int n) { // 8+4 = 12 + + int min = getMin(a, n); // 4 + int max = getMax(a, n); // 4 + int size = max - min + 1; // 4 + std::vector holes(size, 0); // 4*k + 32 + for (int i = 0; i < n; i++) // 4 + holes[a[i] - min] += 1; + int index = 0; // 4 + for (int i = 0; i < size; i++) { // 4 + while (holes[i] > 0) { + a[index] = i + min; + holes[i]--; + index++; + } + } + +} + +bool check(std::vector& a, int n) { + bool monotony_flag = true; + for (int i = 0; i < n-1; i++) { + if (a[i] > a[i + 1]) { + monotony_flag = false; + break; + } + } + return monotony_flag; +} + +void make_array_mixed_again(std::vector& a, int n) { + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + a[i] = 2000000 + i; + } + else { + a[i] = 2000000 - i; + } + } +} + +void generator_pigeon_best(std::vector& a, int n, int val) { + for (int i = 0; i < n; ++i) { + a[i] = static_cast(std::rand() % val); + } +} + +void generator_quick_worst(std::vector& a, int n, int val, int val2) { + for (int i = 0; i < n; i += val2+1) { + a[i] = i + val; + } +} + +void bubbletest() { + + // + std::vector m1(10000, 0); + make_array_mixed_again(m1, 10000); + auto begin = std::chrono::steady_clock::now(); + bubbleSort(m1, 10000); + auto end = std::chrono::steady_clock::now(); + auto elapsed_ms = std::chrono::duration_cast(end - begin); + std::cout << "best bubblesort: " << elapsed_ms.count() << " mcrs" << std::endl; + + assert(check(m1, 10000) == true); + + // / + std::vector m11(10000, 0); + generator(m11, 10000); + auto begin1 = std::chrono::steady_clock::now(); + bubbleSort(m11, 10000); + auto end1 = std::chrono::steady_clock::now(); + auto elapsed_ms1 = std::chrono::duration_cast(end1 - begin1); + std::cout << "average/worst bubblesort: " << elapsed_ms1.count() << " mcrs" << std::endl; + assert(check(m11, 10000) == true); + + std::cout << "success!\n" << std::endl; +} + +void quicktest() { + + // / + std::vector m1(2000, 0); + generator(m1, 2000); + auto begin = std::chrono::steady_clock::now(); + quick_sort(m1, 0, 1999); + auto end = std::chrono::steady_clock::now(); + auto elapsed_ms = std::chrono::duration_cast(end - begin); + std::cout << "best/average quicksort: " << elapsed_ms.count() << " mcrs" << std::endl; + assert(check(m1, 2000) == true); + + // + std::vector m11(2000, 0); + for (int i = 0; i < 2000; i += 10) { + m11[i] = i + 2000000; + } + auto begin1 = std::chrono::steady_clock::now(); + quick_sort(m11, 0, 1999); + auto end1 = std::chrono::steady_clock::now(); + auto elapsed_ms1 = std::chrono::duration_cast(end1 - begin1); + std::cout << "worst quicksort: " << elapsed_ms1.count() << " mcrs" << std::endl; + assert(check(m11, 2000) == true); + + std::cout << "success!\n" << std::endl; +} + +void pigeonholetest() { + // k << n + std::vector m1(10000, 0); + for (int i = 0; i < 10000; i++) { + m1[i] = static_cast(std::rand() % 100); + } + auto begin = std::chrono::steady_clock::now(); + pigeonhole_sort(m1, 10000); + auto end = std::chrono::steady_clock::now(); + auto elapsed_ms = std::chrono::duration_cast(end - begin); + std::cout << "k << n: " << elapsed_ms.count() << " mcrs" << std::endl; + assert(check(m1, 10000) == true); + + // k >> n + std::vector m11(10000, 0); + generator(m11, 10000); + auto begin1 = std::chrono::steady_clock::now(); + pigeonhole_sort(m11, 10000); + auto end1 = std::chrono::steady_clock::now(); + auto elapsed_m1s = std::chrono::duration_cast(end1 - begin1); + std::cout << "k >> n: " << elapsed_m1s.count() << " mcrs" << std::endl; + assert(check(m11, 10000) == true); + + std::cout << "success!\n" << std::endl; +} + + +int main() { + int i; + std::srand(static_cast(std::time(nullptr))); + bubbletest(); + quicktest(); + pigeonholetest(); +} diff --git a/lab5.pdf b/lab5.pdf new file mode 100644 index 00000000..33201858 Binary files /dev/null and b/lab5.pdf differ diff --git a/lab6.cpp b/lab6.cpp new file mode 100644 index 00000000..9140dc58 --- /dev/null +++ b/lab6.cpp @@ -0,0 +1,15 @@ +#include +#include + +int uniquePaths(int m, int n) { // m n = 4+4=8 + std::vector upperrow(n, 1); // 32 + 4*n + + for (int i = 1; i < m; i++) { // i = 4 + std::vector currentrow(n, 1); // 32 + 4*n + for (int j = 1; j < n; j++) { // j = 4 + currentrow[j] = currentrow[j - 1] + upperrow[j]; + upperrow[j] = currentrow[j]; + } + } + return upperrow[n - 1]; +} diff --git a/lab6.pdf b/lab6.pdf new file mode 100644 index 00000000..7c1ee592 Binary files /dev/null and b/lab6.pdf differ