This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
def naive(ar, length): | |
# Наивное решение полным перебором. Сложность - O(n**2). | |
# Проверяем все возможные подмассивы в массиве. | |
# Уверен, что не пройдет по быстродействию. | |
if 0 == length: | |
return 0 | |
if 1 == length: | |
return 1 if ar[0] else 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <thread> | |
#include <vector> | |
std::ostream& operator<<(std::ostream& os, const std::vector<int>& v) | |
{ | |
os << "["; | |
for (const auto& i : v) | |
os << i << ' '; | |
return os << "]"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
std::string Initialize(unsigned short number) | |
{ | |
std::string sequence; | |
sequence.reserve(2 * number); | |
for (auto i = 0; i < number; ++i) | |
sequence += '('; | |
for (auto i = 0; i < number; ++i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse(a): | |
'''Complexity - O(a).''' | |
if a == 0: | |
return 0 | |
result = 0 | |
change = -1 if a > 0 else +1 | |
while a != 0: | |
result += change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
int Task169(const std::vector<int>& first, | |
const std::vector<int>& second, | |
const std::vector<int>& third) | |
{ | |
// Защита от дурака |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <cassert> | |
#include <iostream> | |
#include <memory> | |
template <typename T> | |
class Matrix | |
{ | |
public: | |
Matrix(size_t rows, size_t cols, T value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template <typename T> | |
struct Node | |
{ | |
Node() = default; | |
Node(const T& data) : m_data(data) {} | |
T data() { return m_data; } | |
Node* next() { return m_next.get(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <functional> | |
using std::cout; | |
using std::vector; | |
template <typename ContainerT, bool stable = false> | |
class digsum_sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''https://t.me/unilecs | |
Задача 152. | |
Дана строка слов `string` и массив возможных разделителей `delimiters`. | |
Словом считается последовательность символов между разделителями. | |
Заменить в каждом слове символ с порядковым номером `index` на заданный символ `symbol`. | |
Так как строка - неизменяемый тип данных, то мы вынуждены сначала разбить ее на что-то изменяемое - например, список. | |
Далее работаем со счетчиком символов. Если счетчик равен заданному индексу - заменяем символ. | |
Счетчик сбрасывается по достижении разделителя. | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''https://t.me/unilecs | |
Задача 151. Найти три первых числа Смита, больших заданного числа | |
Число Смита - это составное число, у которого сумма составляющих его цифр равна сумме цифр, составляющих его разложение на простые сомножители. | |
Например: | |
4937775 = 3 * 5 * 5 * 65837, | |
4 + 9 + 3 + 7 + 7 + 7 + 5 = 42, | |
3 + 5 + 5 + 6 + 5 + 8 + 3 + 7 = 42. | |
Поэтому топорный подход "в лоб". Проверяем каждое число, большее заданного. | |
Раскладываем его на простые сомножители, находим суммы цифр, сравниваем. |
NewerOlder