axmet2
05.02.2020 08:06

A. лучший подотрезок ограничение по времени на тест1 секунда ограничение по памяти на тест256 мегабайт вводстандартный ввод выводстандартный вывод вам задан массив a 1 , a 2 ,…, a n a1,a2,…,an . найдите его подотрезок a l , a l+1 ,…, a r al,al+1,…,ar с максимальным значением среднего
арифметического 1 r−l+1 ∑ i=l r a i 1r−l+1∑i=lrai (без какого-либо округления). если существует несколько таких отрезков, то найдите самый длинный. входные данные в первой строке задано единственное целое число n n ( 1≤n≤ 10 5 1≤n≤105 ) — длинна массива a a . во второй строке заданы n n целых
чисел a 1 , a 2 ,…, a n a1,a2,…,an ( 0≤ a i ≤ 10 9 0≤ai≤109 ) — массив a a . выходные данные выведите единственное число — длину наидлиннейшего подотрезка с максимально возможным средним арифметическим. пример входные данные скопировать 5 6 1 6 6 0 выходные данные скопировать 2 примечание
подотрезок [3,4] [3,4] — самы длинный среди всех подотрезков с максимальным средним арифметическим.

Нажмите на рекламу ниже и сразу увидите ответ
Популярные вопросы:
Ответ:
sir228qwerty
02.12.2022 16:52
Function Otr(Ax, Ay, Bx, By: real): real;
begin
  Otr := sqrt(sqr(Ax - Bx) + sqr(Ay - By))
end;

function Perim(Ax, Ay, Bx, By, Cx, Cy: real): real;
begin
  Perim := Otr(Ax, Ay, Bx, By) + Otr(Bx, By, Cx, Cy) + Otr(aX, aY, Cx, Cy);
end;

function Area(Ax, Ay, Bx, By, Cx, Cy: real): real;
var
  pp: real;
begin
  pp := Perim(Ax, Ay, Bx, By, Cx, Cy) / 2;
  Area := sqrt(pp * (pp - Otr(Ax, Ay, Bx, By)) * (pp - Otr(Bx, By, Cx, Cy)) *
    (pp - Otr(Ax, Ay, Cx, Cy)))
end;

procedure Dist(Px, Py, Ax, Ay, Bx, By: real; var D: real);
begin
  D := 2 * Area(Px, Py, Ax, Ay, Bx, By) / Otr(Ax, Ay, Bx, By)
end;

var
  Px, Py, Ax, Ay, Bx, By, Cx, Cy: real;
  d: real;

begin
  writeln('Вводите координаты точкек парами чисел: ');
  write('P-> ');
  readln(Px, Py);
  write('A-> ');
  readln(Ax, Ay);
  write('B-> ');
  readln(Bx, By);
  write('C-> ');
  readln(Cx, Cy);
  writeln;
  Dist(Px, Py, Ax, Ay, Bx, By, d);
  writeln('Расстояние от Р до АВ равно ', d);
  Dist(Px, Py, Cx, Cy, Bx, By, d);
  writeln('Расстояние от Р до ВC равно ', d);
  Dist(Px, Py, Ax, Ay, Cx, Cy, d);
  writeln('Расстояние от Р до АC равно ', d)
end.

Тестовое решение:
Вводите координаты точкек парами чисел:
P-> -3 6
A-> 5 8
B-> 9 -4
C-> 8 -2.5

Расстояние от Р до АВ равно 8.22192191643778
Расстояние от Р до ВC равно 4.43760156980184
Расстояние от Р до АC равно 8.24163383692135
0,0(0 оценок)
Ответ:
FunLayn1
24.04.2023 09:52
У меня есть какие-то наработки, они под линукс, но на винде должно работать все, кроме управления цветом, его выкинешь.

#include <cstdlib>#include <string>#include <iostream>#include "field.h"using namespace std;
int main(int argc, char** argv, char** env){    srand(time(0));    vector< vector< string > > S;    S.resize(2);    S[0].push_back("Vremena_goda");    S[1].push_back("Zima"); S[1].push_back("Vesna"); S[1].push_back("Leto"); S[1].push_back("Osen");
    Field A(S, Field().clGreen, Field().clLightblue);    cout << A << std::endl;    return 0;}
#ifndef FIELD_H_INCLUDED#define FIELD_H_INCLUDED
#include <vector>#include <iterator>#include <algorithm>#include <string>#include <sstream>class Field{public:    enum ConsoleColor { clBlack, clRed, clGreen, clYellow, clBlue, clPurple, clLightblue, clWhite };private:    size_t field_width, field_height;    std::vector< std::vector< std::string > > Data;    std::vector< size_t > column_width;    ConsoleColor color_border, color_font;    std::string get_format_color_string(std::string S, ConsoleColor color)    {        std::stringstream result;        result << "\x1b[1;" << color + 30 << "m" << S << "\x1b[0m";        return result.str();    }    std::string str_mul(std::string s, size_t num)    {        std::string result = "";        for(size_t i = 0; i < num; i++)            result += s;        return result;    }public:    Field() {};    Field(std::vector< std::vector< std::string > > D,          ConsoleColor color_border,          ConsoleColor color_font) :        Data(D), color_border(color_border), color_font(color_font)    {        field_height = Data.size();        field_width = 0;        for(size_t i = 0; i < field_height; i++)            field_width = std::max(field_width, Data[i].size());        for(size_t i = 0; i < field_height; i++)            while(Data[i].size() < field_width)                Data[i].push_back("");        column_width.assign(field_width, 0);        for(size_t i = 0; i < field_height; i++)            for(size_t j = 0; j < field_width; j++)                column_width[j] = std::max(column_width[j], Data[i][j].length());    }    void logs()    {        std::cout << "field_height: " << field_height << std::endl;        std::cout << "field_widht: " << field_width << std::endl;    }    friend std::ostream& operator <<(std::ostream& output_stream, Field & field)    {        /*        std::cout << field.field_width << " " << field.field_height << std::endl;        for(size_t i = 0; i < field.Data.size(); i++)        {            for(size_t j = 0; j < field.Data[i].size(); j++)                std::cout << field.Data[i][j] << " ";            std::cout << std::endl;        }        */
        output_stream << field.get_format_color_string("        ┌", field.color_border);        for(size_t i = 0; i < field.field_width - 1; i++)        {            output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[i] + 2), field.color_border);            output_stream << field.get_format_color_string("┬", field.color_border);        }        output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);        output_stream << field.get_format_color_string("┐\n        ", field.color_border);
        for(size_t i = 0; i < field.field_height; i++)        {            output_stream << field.get_format_color_string("│", field.color_border);            for(size_t j = 0; j < field.field_width; j++)            {                std::stringstream ss;                ss << field.str_mul(" ", field.column_width[j] - field.Data[i][j].size() + 1) << (field.Data[i][j] != "" ? field.Data[i][j] : "");                output_stream << field.get_format_color_string(ss.str(), field.color_font);                output_stream << field.get_format_color_string(" │", field.color_border);            }            output_stream << "\n        ";            if(i != field.field_height - 1)            {                output_stream << field.get_format_color_string("├", field.color_border);                for(size_t j = 0; j < field.field_width - 1; j++)                {                    output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border);                    output_stream << field.get_format_color_string("┼", field.color_border);                }                output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);                output_stream << field.get_format_color_string("┤", field.color_border);            }            else            {                output_stream << field.get_format_color_string("└", field.color_border);                for(size_t j = 0; j < field.field_width - 1; j++)                {                    output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border);                    output_stream << field.get_format_color_string("┴", field.color_border);                }                output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);                output_stream << field.get_format_color_string("┘\n", field.color_border);            }            output_stream << "\n        ";        }        return output_stream;
    }};
#endif // FIELD_H_INCLUDED
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота