Programming Taskbook


E-mail:

Password:

User registration   Restore password

Russian

SFedU SMBU

1100 training tasks on programming

©  M. E. Abramyan (Southern Federal University, Shenzhen MSU-BIT University), 1998–2024

 

Tasks | Task groups | Minmax

PrevNext


Minimums and maximums

All tasks of this section should be solved by means of one-pass algorithms, which require one loop for obtaining result. One-pass algorithms do not need to store all input data simultaneously, so they may be developed without using arrays.

All input sequences in tasks of this group contain one or more elements (in particular, an integer N is always greater than 0).

Since version 4.19, the taskbook includes two versions of this group. The new version, named ZMinmax, differs from the original one in that it associates with dataset elements not order numbers (starting with 1), but indices (starting with 0); the prefix Z in the group name can be interpreted as "zero-indexed". The ZMinmax group is convenient for languages in which elements of arrays and other collections are always indexed from 0. In the ZMinmax group, compared to the Minmax group, the tasks with the following numbers have been changed: 4–11, 13–15, 25, 27–28.

Minmax1°. An integer N and a sequence of N real numbers are given. Find the minimal element and the maximal element of the sequence (that is, elements with the minimal value and the maximal value respectively).

Minmax2. An integer N and a sequence of N rectangles are given. Each rectangle is defined by a pair of its sides (ab). Find the rectangle with the minimal area and output the value of its area.

Minmax3. An integer N and a sequence of N rectangles are given. Each rectangle is defined by a pair of its sides (ab). Find the rectangle with the maximal perimeter and output the value of its perimeter.

Minmax4. An integer N and a sequence of N real numbers are given. Find the order number of the minimal element of the sequence.

Minmax5. An integer N and a sequence of N pairs of real numbers (mv) are given. Each pair of given numbers contains the weight m and the volume v of a detail that is made of some homogeneous material. Output the order number of a detail that is made of the material with maximal density. Also output the corresponding density. Note that the density P can be found by formula

P = m/v.

Minmax6°. An integer N and a sequence of N integers are given. Find the order numbers of the first minimal element and the last maximal element of the sequence.

Minmax7. An integer N and a sequence of N integers are given. Find the order numbers of the first maximal element and the last minimal element of the sequence.

Minmax8. An integer N and a sequence of N integers are given. Find the order numbers of the first and the last minimal elements of the sequence.

Minmax9. An integer N and a sequence of N integers are given. Find the order numbers of the first and the last maximal elements of the sequence.

Minmax10. An integer N and a sequence of N integers are given. Find the order number of the first extremal (that is, minimal or maximal) element of the sequence.

Minmax11. An integer N and a sequence of N integers are given. Find the order number of the last extremal (that is, minimal or maximal) element of the sequence.

Minmax12°. An integer N and a sequence of N real numbers are given. Output the minimal positive number contained in the sequence. If the sequence does not contain positive numbers then output 0.

Minmax13. An integer N and a sequence of N integers are given. Output the order number of the first maximal odd number contained in the sequence. If the sequence does not contain odd numbers then output 0.

Minmax14. A positive real number B and a sequence of 10 real numbers are given. Find the minimum among elements that are greater than B and output its value and its order number. If the sequence does not contain elements greater than B then output 0 twice (the first zero as a real number, the second zero as an integer).

Minmax15. Two real numbers B, C (0 < B < C) and a sequence of 10 real numbers are given. Find the maximum among elements that are in the interval (BC) and output its value and its order number. If the sequence does not contain elements in the interval (BC) then output 0 twice (the first zero as a real number, the second zero as an integer).

Minmax16. An integer N and a sequence of N integers are given. Find the amount of the elements that are located before the first minimal element.

Minmax17. An integer N and a sequence of N integers are given. Find the amount of the elements that are located after the last maximal element.

Minmax18. An integer N and a sequence of N integers are given. Find the amount of the elements that are located between the first and the last maximal element. If the sequence contains the unique maximal element then output 0.

Minmax19°. An integer N and a sequence of N integers are given. Find the amount of the minimal elements of the sequence.

Minmax20. An integer N and a sequence of N integers are given. Find the total amount of all extremal (that is, minimal or maximal) elements of the sequence.

Minmax21. An integer N (> 2) and a sequence of N real numbers are given. The elements of the sequence represent some experimental data. Find the average of the experimental data provided that the minimal and maximal values must be ignored.

Minmax22°. An integer N (> 2) and a sequence of N real numbers are given. Find two smallest elements of the sequence and output their values in ascending order.

Minmax23. An integer N (> 3) and a sequence of N real numbers are given. Find three greatest elements of the sequence and output their values in descending order.

Minmax24. An integer N (> 1) and a sequence of N real numbers are given. Find the maximal sum of two adjacent elements of the sequence.

Minmax25. An integer N (> 1) and a sequence of N real numbers are given. Find two adjacent elements that have the minimal product of their values and output their order numbers in ascending order.

Minmax26. An integer N and a sequence of N integers are given. Output the maximal amount of successive elements whose values are even numbers. If the sequence does not contain even numbers then output 0.

Minmax27. An integer N and a sequence of N integers are given. The sequence contains elements of values 0 and 1 only. Find the longest subsequence of the successive elements with equal values, and output the order number of its initial element and the amount of its elements. If there are several such subsequences then output the order number of the first one.

Minmax28. An integer N and a sequence of N integers are given. The sequence contains elements of values 0 and 1 only. Find the longest subsequence of the successive elements of value 1, and output the order number of its initial element and the amount of its elements. If there are several such subsequences then output the order number of the first one. If the sequence does not contain elements of value 1 then output 0 twice.

Minmax29. An integer N and a sequence of N integers are given. Find the maximal amount of the successive elements with the minimal value.

Minmax30. An integer N and a sequence of N integers are given. Find the minimal amount of the successive elements with the maximal value.


PrevNext

 

  Ðåéòèíã@Mail.ru

Designed by
M. E. Abramyan and V. N. Braguilevsky

Last revised:
01.01.2024