CF35E.Parade

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:64MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

No Great Victory anniversary in Berland has ever passed without the war parade. This year is not an exception. That’s why the preparations are on in full strength. Tanks are building a line, artillery mounts are ready to fire, soldiers are marching on the main square... And the air forces general Mr. Generalov is in trouble again. This year a lot of sky-scrapers have been built which makes it difficult for the airplanes to fly above the city. It was decided that the planes should fly strictly from south to north. Moreover, there must be no sky scraper on a plane’s route, otherwise the anniversary will become a tragedy. The Ministry of Building gave the data on n sky scrapers (the rest of the buildings are rather small and will not be a problem to the planes). When looking at the city from south to north as a geometrical plane, the i-th building is a rectangle of height h__i. Its westernmost point has the x-coordinate of l__i and the easternmost — of r__i. The terrain of the area is plain so that all the buildings stand on one level. Your task as the Ministry of Defence’s head programmer is to find an enveloping polyline using the data on the sky-scrapers. The polyline’s properties are as follows:

  • If you look at the city from south to north as a plane, then any part of any building will be inside or on the boarder of the area that the polyline encloses together with the land surface.
  • The polyline starts and ends on the land level, i.e. at the height equal to 0.
  • The segments of the polyline are parallel to the coordinate axes, i.e. they can only be vertical or horizontal.
  • The polyline’s vertices should have integer coordinates.
  • If you look at the city from south to north the polyline (together with the land surface) must enclose the minimum possible area.
  • The polyline must have the smallest length among all the polylines, enclosing the minimum possible area with the land.
  • The consecutive segments of the polyline must be perpendicular.

Picture to the second sample test (the enveloping polyline is marked on the right).

贝兰德共和国每逢“伟大胜利”周年纪念日,必举行阅兵式,今年也不例外。因此,各项准备工作正在紧锣密鼓地进行:坦克列队成行,火炮阵地整装待发,士兵们在主广场上正步前行……而空军总司令——格纳拉洛夫将军先生,又一次陷入了困境。今年,市内新建了大量摩天大楼,使得飞机难以安全飞越城市上空。经决定,所有飞机必须严格沿由南向北的直线航线飞行;此外,飞机航线上不得存在任何摩天大楼,否则周年庆典将酿成悲剧。

建设部已提供 n 座摩天大楼的数据(其余建筑均较矮小,对飞行不构成威胁)。若从南向北俯视整座城市,并将其建模为一个几何平面,则第 i 座建筑可表示为一个矩形:其高度为 hi,最西端横坐标为 li,最东端横坐标为 ri。该区域地形平坦,所有建筑均建于同一水平面上。

作为国防部首席程序员,你的任务是依据这些摩天大楼数据,构造一条包络折线(enveloping polyline)。该折线需满足以下性质:

  • 若从南向北俯视城市(即视作平面),则任意建筑的任意部分均须位于该折线与地面(即高度为 0 的水平线)所围成的封闭区域内部或边界上;
  • 折线的起点与终点均位于地面高度,即纵坐标(高度)为 0;
  • 折线的所有线段均平行于坐标轴,即仅允许竖直或水平方向的线段;
  • 折线所有顶点的坐标均为整数;
  • 若从南向北俯视,该折线与地面共同围成的区域面积须为所有满足上述条件的折线中最小可能值;
  • 在所有能与地面围成该最小可能面积的折线中,本折线的总长度必须最短;
  • 折线中相邻线段必须互相垂直。

第二个样例测试的示意图(右侧标出的即为所求包络折线)。

输入格式

The first input line contains integer n (1 ≤ n ≤ 100000). Then follow n lines, each containing three integers h__i, l__i, r__i (1 ≤ h__i ≤ 109,  - 109 ≤ l__i < r__i ≤ 109).

第一行输入包含一个整数 nn(1≤n≤1000001 \leq n \leq 100000)。接下来是 nn 行,每行包含三个整数 hih_i、lil_i、rir_i(1≤hi≤1091 \leq h_i \leq 10^9,−109≤li<ri≤109-10^9 \leq l_i < r_i \leq 10^9)。

输出格式

In the first line output integer m — amount of vertices of the enveloping polyline. The next m lines should contain 2 integers each — the position and the height of the polyline’s vertex. Output the coordinates of each vertex in the order of traversing the polyline from west to east. Remember that the first and the last vertices of the polyline should have the height of 0.

第一行输出整数 mm —— 包络折线的顶点数量。接下来的 mm 行每行应包含两个整数 —— 折线顶点的横坐标(位置)和纵坐标(高度)。请按从西向东遍历折线的顺序输出每个顶点的坐标。注意:折线的第一个和最后一个顶点的高度必须为 00。

输入输出样例

  • 输入#1

    2
    3 0 2
    4 1 3

    输出#1

    6
    0 0
    0 3
    1 3
    1 4
    3 4
    3 0
  • 输入#2

    5
    3 -3 0
    2 -1 1
    4 2 4
    2 3 7
    3 6 8

    输出#2

    14
    -3 0
    -3 3
    0 3
    0 2
    1 2
    1 0
    2 0
    2 4
    4 4
    4 2
    6 2
    6 3
    8 3
    8 0

输入解题思路,AI测评打分。不知道怎么写?

首页