PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000077. Đường chân trời của thành phố (The Skyline Problem)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đường chân trời của thành phố (The Skyline Problem)
The Skyline Problem
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Each building is a rectangle with left boundary , right boundary , and height , standing on the ground. Output the skyline as key points from left to right, including the final point of height . Never output adjacent horizontal pieces at the same height.
Input
The first line contains , followed by lines sorted by nondecreasing . This is the stdin/stdout adaptation.
Output
Print the number of key points , then lines of in increasing x order.
Subtasks
- Subtask 1 (20 points): ; ; ; buildings are sorted by nondecreasing .
- Subtask 2 (30 points): ; ; ; buildings are sorted by nondecreasing .
- Subtask 3 (50 points): ; ; ; buildings are sorted by nondecreasing .
Examples
Input
2
0 2 3
2 5 3
Output
2
0 3
5 0
Explanation
Both buildings have height and meet at x-coordinate , so there is no height change there. The only key points are and .