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
using System; | |
namespace Task135cs | |
{ | |
class Program | |
{ | |
/// <summary> | |
/// Еще один рекурсивный метод перебора всех возможных построений пирамиды | |
/// </summary> | |
/// <param name="remainderBlocks">количество оставшихся неиспользованных блоков</param> |
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
/* 01. Метод "Просто посчитать" */ | |
#include <iostream> | |
// Функция вычисления (тут параметр height даже лишний, если не делать проверку на ввод корректных данных) | |
unsigned int calc_pac_man_path(int width, int height, int row, int column) | |
{ | |
// Сначала умножаем номер строки на ширину матрицы и от полученного значения достаточно отнять | |
// количество элементов до номера столбца, в случае если строка четная (значит в этой строке pac-man двигается слева направо), | |
// или отнять ширину матрицы за вычетом номера столбца в случае если строка нечетная (двигается справа налево) | |
return static_cast<unsigned int>(row) * width - (row % 2 == 0 ? column - 1/*единичку отнимаем, чтобы включительно было*/ : width - column); |
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
/* 02. Метод "Честный PacMan" */ | |
using System; | |
namespace Task133cs | |
{ | |
class Program | |
{ | |
// Подсчет количества пройденное PacMan`ом, по честному как в задании | |
public static ulong CalcPacManPath(int width, int height, int row, int column) |
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
/* 01. Метод "Просто посчитать" */ | |
#include <iostream> | |
// Функция вычисления (тут параметр height даже лишний, если не делать проверку на ввод корректных данных) | |
unsigned int calc_pac_man_path(int width, int height, int row, int column) | |
{ | |
// Сначала умножаем номер строки на ширину матрицы и от полученного значения достаточно отнять | |
// количество элементов до номера столбца, в случае если строка четная (значит в этой строке pac-man двигается слева направо), | |
// или отнять ширину матрицы за вычетом номера столбца в случае если строка нечетная (двигается справа налево) | |
return static_cast<unsigned int>(row) * width - (row % 2 == 0 ? column - 1/*единичку отнимаем, чтобы включительно было*/ : width - column); |
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
// Learn more about F# at http://fsharp.org | |
// See the 'F# Tutorial' project for more help. | |
open System.Diagnostics | |
open System.Threading.Tasks | |
// Получить все разбиения на слагаемые | |
let GetAllPartitions(n:int) : Task<uint64> = | |
async { | |
// Переменная для подсчета количества разложений | |
let mutable count = 0UL | |
// Вывод на экран |
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
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
namespace Task130cs | |
{ | |
class Program | |
{ | |
// Счетчик количества разложений на слагаемые |
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
// Learn more about F# at http://fsharp.org | |
// See the 'F# Tutorial' project for more help. | |
// Если число разбивать на Х слагаемых и мы ищем максимальное произведение этих слагаемых, то имеет место быть следующее неравенство | |
// | |
// s1 + s2 + ... + sX x ___________________ | |
// ------------------ >= _ / | |
// X \/ s1 * s2 * .. * sX | |
// | |
// С учётом этого несложно понять, что неравенство превращается в равенство только тогда, когда s1=s2=...=sX= N / X |
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> | |
/// Пытаясь разложить небольшие числа на слагаемые, произведение которых максимально, то легко можно заметить закономерность, | |
/// что максимальное произвидение достигается, когда большинство слагаемых = 3. Как это объснить, я пока не знаю, но с радостью воспользуюсь этой закономерностью. | |
/// Используя это - выделим три частных случая: | |
/// 1) когда число кратно трем, тогда можно его представить всеми тройками; | |
// N%3==0 => N=3+..(N/3 раз)..+3 => MaxP=3*..(N/3 раз)..*3 | |
/// 2) когда остаток от деления = 1, то 1 в произвидении не даст нам ничего, поэтому эту единицу лучше сложить с последней тройкой; | |
// N%3==1 => N=3+..(N/3 раз)..+3+1 = 3+..(N/3-1 раз)..+3+4 => MaxP=3*..(N/3-1 раз)..*3*4 | |
/// 3) когда остаток от деления = 2, то он и остаётся последним слагаемым и множителем | |
// N%3==2 => N=3+..(N/3 раз)..+3+2 => MaxP=3*..(N/3 раз)..*3*2 |
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
using System; | |
namespace Task126cs | |
{ | |
class Program | |
{ | |
// Самый надежный и самый "тяжелый способ" - перебор всех сочетаний алфавита и исключние тех, в которых есть подстрока | |
private static uint NumberOfPosibleOption(char[] sourceAlphabet, int lengthOption, string exceptSubstring) | |
{ | |
// Инициализируем счетчики |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Task124cs | |
{ | |
class Program | |
{ | |
// Рекурсивный метод для перебора всех возможных наборов сумм подмасивов | |
// Первый параметр - для сравнения с точной половиной суммы основного массива |