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

акылды уй тест курастыру

Показать ответ
Ответ:
Саняша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 оценок)
Ответ:
basarbakhtiar
basarbakhtiar
03.12.2020 15:08

/*Решение с обобщения формула Брахмагупты для произвольного четырехугольника. Функция perimeter(double x[], double y[]) возвращает значение периметра, функция area(double x[], double y[]) возвращает значение площади, пример использования и реализация приведены ниже. */

#include <iostream>

#include <math.h>

double perimeter(double x[], double y[]);

double area(double x[], double y[]);

int main()

{

   double x[4], y[4];

   std::cout << "Quadrangle ABCD\n";

   for (auto i = 0; i < 4; i++)

   {

       std::cout << "Input coordinates of point " << char(i + 'A') << ": ";

       std::cin >> x[i] >> y[i];

   }

   std::cout << perimeter(x, y) << " " << area(x, y);

   

   return 0;

}

double perimeter(double x[], double y[])

{

   double a[4], p = 0;

   for (auto i = 0; i < 4; i++)

   {

       a[i] = sqrt((x[i]-x[(i + 1) % 4]) * (x[i]-x[(i + 1) % 4]) + (y[i]-y[(i + 1) % 4]) * (y[i]-y[(i + 1) % 4]));

       p += a[i];

   }

   return p;

}

double area(double x[], double y[])

{

   double a[4], p = 0, s = 1, d[2];

   for (auto i = 0; i < 4; i++)

   {

       a[i] = sqrt((x[i]-x[(i + 1) % 4]) * (x[i]-x[(i + 1) % 4]) + (y[i]-y[(i + 1) % 4]) * (y[i]-y[(i + 1) % 4]));

       p += a[i];

   }

   for (auto i = 0; i < 4; i++)

   {

       s *= (p / 2- a[i]);

   }

   for (auto i = 0; i < 2; i++)

   {

       d[i] = sqrt((x[i]-x[i + 2]) * (x[i]-x[i + 2]) + (y[i]-y[i + 2]) * (y[i]-y[i + 2]));

   }

   s -= (a[0] * a[2] + a[1] * a[3] + d[0] * d[1]) * (a[0] * a[2] + a[1] * a[3] - d[0] * d[1]) / 4;

   s = sqrt(s);

   return s;

}

0,0(0 оценок)
Популярные вопросы: Информатика
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота