В
Все
М
Математика
А
Английский язык
Х
Химия
Э
Экономика
П
Право
И
Информатика
У
Українська мова
Қ
Қазақ тiлi
О
ОБЖ
Н
Немецкий язык
Б
Беларуская мова
У
Українська література
М
Музыка
П
Психология
А
Алгебра
Л
Литература
Б
Биология
М
МХК
О
Окружающий мир
О
Обществознание
И
История
Г
Геометрия
Ф
Французский язык
Ф
Физика
Д
Другие предметы
Р
Русский язык
Г
География
sashkaaaxo
sashkaaaxo
12.06.2022 23:46 •  Информатика

Заполните трассировочную таблицу по данной блок-схеме: [2]​


Заполните трассировочную таблицу по данной блок-схеме: [2]​

Показать ответ
Ответ:
Саняша69
Саняша69
21.11.2021 10:50
Код#include <iostream>#include <utility>#include <numeric>#include <vector>class Beast {    int trigger;    double aggression;    double rage_aggression;public:    Beast() = default;    Beast(int trigger, double aggression, double range_aggression)    : trigger(trigger), aggression(aggression), rage_aggression(range_aggression)    { }    Beast(const Beast&) = default;    Beast(Beast&&) = default;    Beast& operator=(const Beast&) = default;    Beast& operator=(Beast&&) = default;    [[nodiscard]] double calculate_aggression(unsigned long amount) const {        return amount > trigger ? rage_aggression : aggression;    }    void ReadFrom (std::istream& is) {        is >> aggression >> rage_aggression >> trigger;    }    void WriteTo(std::ostream &os) const {        os << aggression << " " << rage_aggression << " " << trigger;    }};std::istream& operator >>(std::istream &is, Beast &cls) {    cls.ReadFrom(is);    return is;}std::ostream& operator <<(std::ostream &os, const Beast &cls) {    cls.WriteTo(os);    return os;}class Cage {    double durability;    std::vector<Beast> container;public:    explicit Cage(double durability, std::vector<Beast> container)    : durability(durability), container(std::move(container))    { }    Cage(const Cage&) = default;    Cage(Cage&&) = default;    Cage& operator=(const Cage&) = default;    Cage& operator=(Cage&&) = default;    [[nodiscard]] double calculate_aggressive() const {        auto amount = container.size();        if (amount == 0) return 0;        return std::accumulate(container.begin(), container.end(), 0.0,        [amount](double total_aggressive, const Beast & beast){            return total_aggressive + beast.calculate_aggression(amount);        });    }    [[nodiscard]] bool is_it_normal() const {        auto aggressive = calculate_aggressive();        return aggressive <= durability;    }    [[nodiscard]] int get_capacity() const {        return container.size();    }    [[nodiscard]] double get_durability() const {        return durability;    }};template <typename T>void subsetsUtil(std::vector<T>& A, std::vector<std::vector<T> >& res,                 std::vector<T>& subset, int index){    res.push_back(subset);    for (int i = index; i < A.size(); i++) {        // include the A[i] in subset.        subset.push_back(A[i]);        // move onto the next element.        subsetsUtil(A, res, subset, i + 1);        // exclude the A[i] from subset and triggers        // backtracking.        subset.pop_back();    }}template <typename T>std::vector<std::vector<T>> P(std::vector<T>& A){    std::vector<T> subset;    std::vector<std::vector<T>> res;    int index = 0;    subsetsUtil(A, res, subset, index);    return res;}int main () {    int n, s;    Beast noname{};    std::vector<Beast> set_of_beasts;    std::cin >> n >> s;    for (auto i = 0; i < n; ++i) {        std::cin >> noname;        set_of_beasts.push_back(noname);    }    auto selections = P(set_of_beasts);    std::vector<Cage> variants;    std::transform(selections.begin(), selections.end(), std::back_inserter(variants), [s](std::vector<Beast> &selection){        return Cage(s, selection);    });    std::vector<Cage> true_variants;    std::copy_if(variants.begin(), variants.end(), std::back_inserter(true_variants), [](Cage& x) {return x.is_it_normal();});    auto the_best_of_the_best_variant = *std::max_element(true_variants.begin(), true_variants.end(), [](Cage & s1, Cage & s2){        return s1.get_capacity() < s2.get_capacity();    });    std::cout << the_best_of_the_best_variant.get_capacity();    return 0;}
У Арсения есть n зверьков. Каждый из них обладает характером, поэтому, если в клетке, где находится
У Арсения есть n зверьков. Каждый из них обладает характером, поэтому, если в клетке, где находится
0,0(0 оценок)
Ответ:
alina1930
alina1930
06.09.2022 01:45
// PascalABC.NET 3.0, сборка 1073
const
  nn=30;
  mm=30;
var
  a:array[1..mm,1..nn] of integer;
  m,n,i,j,k,s:integer;
begin
  Writeln('Введите число строк и столбцов массива: '); Read(m,n);
  Randomize;
  Writeln('*** Исходный массив ***');
  k:=0;
  for i:=1 to m do begin
    for j:=1 to n do begin
      a[i,j]:=Random(51)-25;
      Write(a[i,j]:4);
      if Odd(a[i,j]) then Inc(k)
    end;
    Writeln
  end;
  if k>5 then begin
    Writeln('Средние арифметические отрицательных элементов по строкам');
    for i:=1 to m do begin
      s:=0; k:=0;
      for j:=1 to n do
        if a[i,j]<0 then begin Inc(k); s:=s+a[i,j] end;
      if k>0 then Writeln(s/k:9:5) else Writeln('  0.00000');
    end
  end
  else begin
    Writeln('*** Результирующий массив ***');
    for i:=1 to m do begin
      for j:=1 to n do begin a[i,j]:=2*a[i,j]; Write(a[i,j]:4) end;
    Writeln
    end
  end
end.

Тестовые решения:
Введите число строк и столбцов массива:
8 6
*** Исходный массив ***
 -16  -8  -1  24 -22   1
  -9 -20 -25  13 -11  10
 -15  10 -12  20 -22   3
  -6  25  -3  25 -14  22
  24  -4  24  17  -4 -17
 -23  -9 -22   1 -18 -13
 -12  13   6 -16   2 -13
  19   8 -22  14  -3   4
Средние арифметические отрицательных элементов по строкам
-11.75000
-16.25000
-16.33333
 -7.66667
 -8.33333
-17.00000
-13.66667
-12.50000

Введите число строк и столбцов массива:
3 5
*** Исходный массив ***
   3  24 -21 -22  -8
 -21  14 -22   0 -22
  15 -16  -2   6  22
*** Результирующий массив ***
   6  48 -42 -44 -16
 -42  28 -44   0 -44
  30 -32  -4  12  44
0,0(0 оценок)
Популярные вопросы: Информатика
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота