Last active
August 12, 2022 18:28
-
-
Save gmakc-094423/c0e4fb3e17f782c2bf6de863c88f8294 to your computer and use it in GitHub Desktop.
Домашнее задание к 10 семинару
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
// Задача 73: Есть число N. Сколько групп M, можно получить при разбиении всех чисел на группы, так чтобы в одной группе все числа были взаимно просты (все числа в группе друг на друга не делятся)? Найдите M при заданном N и получите одно из разбиений на группы N ≤ 10²⁰. Можно использовать рекурсию. | |
int n = InputNumbers("Введите число N: "); | |
int[] tempArray = CreateArray(n); | |
CreateRows(tempArray); | |
void CreateRows(int[] arrayCheck) | |
{ | |
int[] arrayTemp = new int[arrayCheck.Length]; | |
int m = 1; | |
int count = 0; | |
int tempNumber = 0; | |
int tempNumber2 = 0; | |
int tempSwitch = 0; | |
for (int i = 0; i < arrayCheck.Length; i++) | |
{ | |
Array.Clear(arrayTemp); | |
count = 0; | |
if (arrayCheck[i] != 0) | |
{ | |
arrayTemp[count] = arrayCheck[i]; | |
tempNumber2 = arrayCheck[i]; | |
for (int j = i; j < arrayCheck.Length; j++) | |
{ | |
if (arrayCheck[j] % tempNumber2 != 0 || arrayCheck[j] / tempNumber2 == 1) | |
{ | |
tempSwitch = 0; | |
tempNumber = arrayCheck[j]; | |
for (int k = 0; k < count; k++) | |
{ | |
if (tempNumber % arrayTemp[k] == 0) tempSwitch++; | |
} | |
if (tempSwitch == 0) | |
{ | |
arrayTemp[count] = arrayCheck[j]; | |
count++; | |
arrayCheck[j] = 0; | |
} | |
} | |
} | |
Console.WriteLine($"Группа {m++}: {PrintIntArray(arrayTemp)}"); | |
} | |
} | |
} | |
int InputNumbers(string input) | |
{ | |
Console.Write(input); | |
int output = Convert.ToInt32(Console.ReadLine()); | |
return output; | |
} | |
int[] CreateArray(int n) | |
{ | |
int[] temp = new int[n]; | |
for (int i = 0; i < temp.GetLength(0); i++) | |
{ | |
temp[i] = i + 1; | |
} | |
return temp; | |
} | |
string PrintIntArray(int[] array) | |
{ | |
string result = string.Empty; | |
for (int i = 0; i < array.Length; i++) | |
{ | |
if (array[i] != 0) result += $"{array[i],1} "; | |
} | |
return result; | |
} |
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
// Задача 74*: 4 друга должны посетить 12 пабов, в котором выпить по британской пинте пенного напитка. До каждого бара идти примерно 15-20 минут, каждый пьет пинту за 15 минут. У первого друга лимит выпитого 1.1 литра, у второго 1.5, у третьего 2.2 литра, у 4 - 3.3 литра, это их максимум. Необходимо выяснить, до скольки баров смогут дойти каждый из друзей(Пройденное расстояние (в барах)), пока не упадет. И сколько всего времени будет потрачено на выпивку. | |
double[] frendsLimit = new double[]{1.1, 1.5, 2.2, 3.3}; | |
int speedDrinking = 15; | |
int[] walkingSpeed = new int[]{15, 20}; | |
int travelTime = 0; | |
int pubsQuantity = 12; | |
double pint = 0.56826125; | |
int timeСounter = 0; | |
for (int j = 0; j <= frendsLimit.Length - 1; j++) | |
{ | |
int count = 0; | |
travelTime = -17; | |
while (frendsLimit[j] > 0) | |
{ | |
frendsLimit[j] -= pint; | |
count++; | |
travelTime = travelTime + new Random().Next(walkingSpeed[0], walkingSpeed[1] + 1); | |
} | |
timeСounter = travelTime + speedDrinking * count; | |
if (count > pubsQuantity) Console.WriteLine($"Друг № {j + 1} пошел на 2-й круг и упадёт в {count-12} баре через {timeСounter / 60} часов {timeСounter % 60} минут"); | |
else | |
{ | |
Console.WriteLine($"Друг № {j + 1} упадёт в {count} баре через {timeСounter / 60} часов {timeСounter % 60} минут"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment