This file contains hidden or 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 <cmath> | |
#include <ostream> | |
// Трёхкомпонентный вектор | |
struct vec3 | |
{ | |
double x, y, z; | |
// Длина вектора | |
double length() const { |
This file contains hidden or 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
; Speed Test for Windows x64, v1.01 / fasm 1 | |
; (c) 2020 Jin X ([email protected]) | |
format PE64 Console 5.0 | |
include 'win64axp.inc' | |
define REQUIRE_ADMIN_RIGHTS 1 ; 1 - run with the highest (realtime) priority, 0 - run with just high priority | |
;-- CODE SECTION ------------------------------------------------------------------------------------------------------- |
This file contains hidden or 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
/*********************************************************************************************************************** | |
Задача UniLecs №273: https://telegra.ph/Anons-273-Najti-podmassivy-gde-summa-ehlementov-ravna-zadannomu-chislu-K-06-11 | |
Решение задачи о поиске кол-ва подмассивов, где сумма элементов равна заданному числу. | |
________________________________________________________________________________________________________________________ | |
Идея решения с линейной сложностью довольна проста. Заводим хеш-таблицу (unordered_map), ключом которого будет сумма, | |
а значением – кол-во таких сумм. Инициализируем переменную current_sum = 0 (сумму элементов от начала массива). Далее | |
перебираем все элементы исходного массива и внутри цикла делаем следующие шаги: |
This file contains hidden or 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
/*********************************************************************************************************************** | |
Задача UniLecs №271: https://telegra.ph/Anons-271-Obedinenie-otsortirovannyh-svyazannyh-spiskov-05-27 | |
Алгоритм №0A решения задачи об объединении отсортированных связных списков (самый быстрый и правильный алгоритм) :) | |
Алгоритм с использованием приоритетной очереди. | |
Модификация с обработкой списков как с восходящими, так и с нисходящими сортировками (определяются автоматически). | |
________________________________________________________________________________________________________________________ | |
Добавим в приоритетную очередь итераторы, указывающие на начало каждого списка (только для непустых списков). |
This file contains hidden or 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
/*********************************************************************************************************************** | |
Задача UniLecs №272: https://telegra.ph/Anons-272-Vosstanovit-cifry-iz-peremeshannyh-bukv-06-04 | |
Алгоритм №1A решения задачи на восстановление цифр из перемешанных букв. | |
Вариант работы со счётчиками букв. | |
________________________________________________________________________________________________________________________ | |
Разберём запись числительных от 0 до 9 на английском языке и посчитаем кол-во букв в строке, содержащей их все. Получим | |
следующую статистику: |
This file contains hidden or 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
/*********************************************************************************************************************** | |
Задача UniLecs №271: https://telegra.ph/Anons-271-Obedinenie-otsortirovannyh-svyazannyh-spiskov-05-27 | |
Алгоритм №0A решения задачи об объединении отсортированных связных списков (самый быстрый и правильный алгоритм) :) | |
Алгоритм с использованием приоритетной очереди. | |
________________________________________________________________________________________________________________________ | |
Добавим в приоритетную очередь итераторы, указывающие на начало каждого списка (только для непустых списков). |
This file contains hidden or 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
/*********************************************************************************************************************** | |
Задача UniLecs №270: https://telegra.ph/Anons-270-SHahmatnyj-ehtyud-05-21 | |
Алгоритм №1 решения задачи о ферзях (самый быстрый и минималистичный по коду и использованию памяти). | |
Будем расставлять по 1 ферзю в каждом ряду доски. Сначала будем перебирать позиции первого ряда (с некоторой поправкой, | |
см. ниже), затем рекурсивно второго, третьего и т.д. Для хранения информации о недоступных позициях (позициях, находящихся | |
под ударом других ферзей) заведём 3 переменные: busy_x (занятые вертикальные колонки), busy_ldiag (занятые колонки левой | |
диагонали для текущего ряда), busy_rdiag (занятые колонки правой диагонали для текущего ряда). Данные в этих переменных |
This file contains hidden or 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 <string> | |
// Convert positive integer 1..3999 to roman number string | |
// Empty string is returned for out-of-range values | |
std::string int_to_roman(int n) | |
{ | |
// Range check | |
if (n < 1 || n > 3999) { return ""; } | |
// Roman digits and result string |
This file contains hidden or 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
/*********************************************************************************************************************** | |
Задача UniLecs №269: https://telegra.ph/Anons-269-CHisla-propisyu-05-14 | |
Преобразование выполняется блоками по 1000, т.е. сначала миллиарды, затем миллионы, затем тысячи и, наконец, единицы. | |
В каждом блоке сначала проверяются сотни, затем значения 11..19, затем десятки, затем единицы. | |
Подробный алгоритм описан ниже. | |
1. Особый случай: если n = 0, возвращаем "zero". |
This file contains hidden or 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
// Sieve of Eratosthenes | |
// (c) 2021 Jin X ([email protected]) | |
#include <vector> | |
#include <cmath> | |
#include <stdexcept> | |
// Sieve of Eratosthenes class | |
class EratosthenesSieve | |
{ |
NewerOlder