Loading [MathJax]/extensions/tex2jax.js

����������

A: ������� ���� �����

�������� ������� int median(int a, int b, int c), ������� �������� �� ���� ��� ����� � ���������� �� ������� (������� �� ��� ��������).

������ �� �������� ������ ���� �������.

����� ������� ������������ ��������
median(1, 9, 7)
7

B: ����������� �� ����� �������� - 1

���� ��� �������������� ����� \(x\) � \(y\). ���������, ����������� �� ����� � ������������ \((x,y)\) ��������������� �������� (������� ��� �������). �� ������� ����� ��������� � ����� 1.

������� �������� � ���� ������� bool is_point_in_square(double x, double y), ������������ true, ���� ����� ����������� �������� � false, ���� �� �����������.

������� is_point_in_square �� ������ ��������� ���������� if.

������ �� �������� ������ ���� �������.

����� ������� ������������ ��������
is_point_in_square(0, 0)
true
is_point_in_square(3, -7)
false

C: ����������� �� ����� �������� - 2

������ ����������� ������ ��� ������ ��������:

������� ������ ��������������� ����������� ��� ������� ������ C.

������� ������ ���������� is_point_in_rhombus.

����� ������� ������������ ��������
is_point_in_rhombus(0, 0)
true
is_point_in_rhombus(1, 1)
false

D: ����������� �� ����� �����

���� ���� �������������� �����: \(x\), \(y\), \(x_c\), \(y_c\), \(r\). ���������, ����������� �� ����� \((x,y)\) ����� � ������� \((x_c,y_c)\) � �������� \(r\).

������� �������� � ���� ������� bool is_point_in_circle(double x, double y, double xc, double yc, double r).

������� ������ ��������������� ����������� ��� ������� ������ C.

����� ������� ������������ ��������
is_point_in_circle(0.5, 0.5, 0, 0, 1)
true
is_point_in_circle(0.5, 0.5, 1, 1, 0.1)
false

E: ����������� �� ����� �������

���������, ����������� �� ����� ������ ����������� �������. ������� ������������ �����.

������� �������� � ���� ������� bool is_point_in_area(double x, double y).

������� ������ ��������������� ����������� ��� ������� ������ �.

����� ������� ������������ ��������
bool is_point_in_area(-1, 2)
true
bool is_point_in_area(0, 0)
false

F: ���������� �����

���� �����, �������� �����, ������������ �� ��� �� ����, ���������� � �������� �������.

������� �������� � ���� ������� int reverse(int n), ������� �������� �� ���� �������� ���� int � ���������� �������� ���� int.

����� ������� ������������ ��������
reverse(179)
971

G: ����������� �������� �����

���� ����������� ����� \(n>1\). ������� ��� ���������� ��������, �������� �� 1.

������� �������� � ���� ������� long long min_divisor(long long n). �������� ������ ����� ��������� \(O(\sqrt{n})\). �������� �������� �� ������������ ��� ������.

��������. ���� � ����� \(n\) ��� �������� �� �������������� \(\sqrt{n}\), �� ����� \(n\) — ������� � ������� ����� ���� ����� \(n\).

������ �� �������� ������ ���� �������.

����� ������� ������������ ��������
min_divisor(4)
2
min_divisor(5)
5

H: �������� ����� �� ��������

���� ����������� ����� \(n>1\). ���������, �������� �� ��� �������. ��������� ������ ������� ����� YES, ���� ����� ������� � NO, ���� ����� ���������.

������� �������� � ���� ������� bool is_prime(long long n), ������� ���������� true ��� ������� ����� � false ��� ��������� �����. ������� ������ ����� ��������� \(O(\sqrt{n})\).

������ �� �������� ������ ���� �������.

����� ������� ������������ ��������
is_prime(2)
true
is_prime(4)
false

I: ��������� �����

���� ��� ����������� ����� \(n\) � \(m\). ��������� ����� \(\frac{n}{m}\), �� ���� �������� ��� ������ ����� \(p\) � \(q\) �����, ��� \(\frac{n}{m}=\frac{p}{q}\) � ����� \(\frac{p}{q}\) — ������������.

������� �������� � ���� ������� void reduce_fraction(int & n, int & m), ���������� �������� nm �� ������ � ���������� ��.

������ �� �������� ������ ���� �������.

�������� n, m �� ������ �������� n, m ����� ������ reduce_fraction(n, m)
\(n=12\), \(m=16\) \(n=3\), \(m=4\)

J: ������� � ��������

������ ������������� ��� � ����������� � ���, ��� ����� ������� � �������� ��� ������������� ����� ����������. ��������, ��� ��� ������� ����� \(a\) �� ����� \(b\) � �������� ��������� ����� ����� \(q\) (�������) � \(r\) (�������), ��� \(a=qb+r\). ��� ���� \(|r|<|b|\). ���� ����� \(a\) � \(b\) — �������������, �� ����������� ����� ������� �����������: \(0 \le r < b\) � ����� ������� � �������� ������������ ����������. �� ���� ����� — ������������� �� ������� � �������� �� ���������� ����������� �� ���, ��� ��� ������� ���������� �����������.

��� ��� ����������� ������� � �������� �� ���������� ��� ������������� �����:

a
b
a / b
a % b
26
10
2
6
-26
10
-2
-6
26
-10
-2
6
-26
-10
2
-6

����� �������, � ���������� ������������� ������� �������� ����������� ���������� ��������������� �������� � ������� ����, ��� ��� ������ ������� trunc. ����� ���, ��������� �������, ��� ������������� ������� — ��� ����� ����� �� �������� \((q=\lfloor a/b\rfloor)\), �� ���� ��������� ������������� ������� floor. ��� ���� ����� ���������� � ����� ������ ����������:

\(a\) \(b\) \(\lfloor a / b\rfloor\) \(a \bmod b\)
26
10
2
6
-26
10
-3
4
26
-10
-3
-4
-26
-10
2
-6

�������� ���������, ������� �� ������ ������ \(a\) � \(b\) ��������� �� ������������� ������� � ������� �� ������� ���, ��� ��� ������� � ����������. ��������� �� ������ ������������ �������������� ����� � �����.

������� �������� � ���� ������� void div_mod(int a, int b, int & q, int & r), ��� a — �������, b — ��������, q — ���������� ��� ������ ��������, r — ���������� ��� ������ �������.

������ �� �������� ������ ���� �������.

�������� \(a\), \(b\) �� ������ �������� \(q\), \(r\) ����� ������
\(a=-26\), \(b=10\) \(q=-3\), \(r=4\)
\(a=26\), \(b=-10\) \(q=-3\), \(r=-4\)

K: ����������� ������ �����

���� ������ ����� ����� \(a\), \(b\), \(c\), \(d\). ����������� ��� ����� � ������� ����������, �� ���� ���������� ����������� �� �������� ���, ����� \(a\le b\le c\le d\). ������� �������� � ���� ������� void sort(int & a, int & b, int & c, int & d).

������� ������ ��������� ������ �������� ����

if (a > b)
    swap(a, b);

��������� ���������� if �� �����������. ������ ����� ���������� if ����� ���� ������ ���� swap. ����� else ���� ������������ �� �����.

������ �� �������� ������ ���� �������.

�������� \(a\), \(b\), \(c\), \(d\) �� ������ �������� ����� ������ sort(a, b, c, d)
\(a=3\), \(b=2\), \(c=4\), \(d=1\) \(a=1\), \(b=2\), \(c=3\), \(d=4\)

K+: ����������� ����� ������� (������ �� ��������)

����� ���������� ���������� ������� ����� ��������� ������� ���������� ������?