COCI 2010/2011 Task PROFESOR 1 st round, October 23rd 2010 Author: Goran Gašić In a long classroom, N desks are arranged in a single row, with two students sitting at each desk. Students are cranky because they are about to have an art class, and their professor is planning to examine them. Each student has studied art, but only to a certain level. The old professor can tell by the looks on their faces just how much they have studied. The professor, being an artist, uses a different coloured pencil for each grade. Unfortunately, today he brought only one pencil. In order to make the examination seem fair, he wants to choose two desks and question one student from each desk positioned between the two desks he has chosen (including the chosen desks). It is important that all examined students deserve the same grades, so he can write them down using his only pencil. The professor wants to know the maximum number of students he can examine this way, as well as which grade the students will get. INPUT The first line of input contains a single integer N (1 ≤ N ≤ 100 000). Each of the following N rows contains two integers: Ai and Bi , grades deserved by students sitting at desk i (1 ≤ Ai , Bi ≤ 5). OUTPUT The first and only line of output must contain two numbers separated by a single space: the maximum number of students the professor can examine and the grade those students will get. If there are multiple solutions possible, output the one with the smallest grade. SCORING Test cases worth 70% of total points have N ≤ 100. SAMPLE TESTS input 1 1 5 output 1 1 input 3 3 5 4 5 1 3 output 2 5 input 4 2 1 3 2 5 3 2 5 output 2 2 нужно решить на паскале
a) 5 * 2 - 4
Решение:
Умножение имеет более высокий приоритет, чем вычитание. Поэтому, сначала выполним вычисление умножения: 5 * 2 = 10.
Затем, выполним вычитание: 10 - 4 = 6.
Ответ: 6.
б) 7 * х + 2
Решение:
Умножение имеет более высокий приоритет, чем сложение. Поэтому, сначала выполним вычисление умножения: 7 * х = 7х.
Затем, выполним сложение: 7х + 2.
Ответ: 7х + 2.
в) 8 * х - 3 * (х + у)
Решение:
Выполним умножение: 8 * х = 8х и 3 * (х + у) = 3х + 3у.
Затем, выполним вычитание: 8х - (3х + 3у).
Для выполнения операции в скобках, умножение 3 на каждый из элементов внутри скобок:
8х - 3х - 3у = 5х - 3у.
Ответ: 5х - 3у.
г) v^2 * х * у^2 * х * у
Решение:
По правилам алгебры, умножение можно проводить в любом порядке.
Выполним умножение: v^2 * х = v^2х, у^2 * х = у^2х, v^2х * у^2х = (vх * у)^2х.
Ответ: (vх * у)^2х.
2. Переведем запись с языка Pascal в нормальную форму:
f = (3 * x + 4 * y)/(2 * sqr(к) - 4 * t / y)
Решение:
Нормализация выражения подразумевает разделение на более простые составляющие.
Заменим sqr(к) на к^2, чтобы выразить возведение в квадрат в общепринятой форме:
f = (3 * x + 4 * y)/(2 * к^2 - 4 * t / y)
Затем, выполним умножение и деление в числителе и знаменателе:
f = (3 * x + 4 * y)/(2к^2 - (4 * t) / y)
Ответ: f = (3 * x + 4 * y)/(2к^2 - 4t/y).
Таким образом, мы записали выражения по правилам языка Pascal и перевели запись с языка Pascal в нормальную форму.