Analysis of the real questions of the C/C++ Programming Level Examination of the Institute of Electronics in December 2022 (Level 6)

All real questions of C/C++ level exam (Level 1~8)・Click here

Question 1: Interval merging (2022-12-Level 6)

Given n closed intervals [ai; bi], where i=1,2,...,n. Any two adjacent or intersecting closed intervals can be merged into a closed interval. For example, [1;2] and [2;3] can be combined into [1;3], [1;3] and [2;4] can be combined into [1;4], but [1;2] and [ 3;4] cannot be merged.
Our task is to determine whether these intervals can be finally merged into a closed interval. If so, output the closed interval, otherwise output no.
Time limit: 1000
Memory limit: 65536
Input
The first line is an integer n, 3 ≤ n ≤ 50000. Indicates the number of input intervals. The next n lines, on the i-th line (1 ≤ i ≤ n), are two integers ai and bi. The integers are separated by a space, indicating the interval [ai; bi] (where 1 ≤ ai ≤ bi ≤ 10000) .
Output
Output a line. If these intervals can eventually be merged into a closed interval, output the left and right boundaries of the closed interval, separated by a single space; otherwise, output no.
 
Sample input<

Supongo que te gusta

Origin blog.csdn.net/gozhuyinglong/article/details/135072712
Recomendado
Clasificación