CF1776B.Vittorio Plays with LEGO Bricks
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vittorio is playing with his new LEGO Duplo bricks. All the bricks have the shape of a square cuboid with a 2×2 square base and a height of 1. They can be arranged in the 3D space to build structures, provided that the following rules are met:
- No two bricks can intersect, but they can touch on their faces.
- The corners of every brick must have integer coordinates (so bricks are axis-aligned) and the z coordinates of all corners must be non-negative.
- The square bases of every brick must be parallel to the ground (i.e. the plane z=0).
- The lower base of any brick that is not touching the ground must touch the upper base of some other brick in a region of positive area (when this happens, the two bricks stay attached to each other thanks to small studs).
For example, this is a valid structure:

Vittorio wants to build a structure that includes purple bricks in the following n positions: (x1,0,h), (x2,0,h), …, (xn,0,h) — these are the coordinates of the centers of their lower bases; note that all of these bricks have y coordinate equal to 0 and z coordinate equal to h. Vittorio will use additional bricks of other colors to support the purple bricks. He is willing to place bricks only in positions where the center of the lower base has y coordinate equal to 0. What is the minimum number of additional bricks needed?
It can be shown that a valid construction always exists.
维托里奥正在玩他的新乐高得宝(LEGO Duplo)积木。所有积木均为底面为 2×2 正方形、高为 1 的长方体。它们可在三维空间中堆叠以构建结构,但需满足以下规则:
- 任意两块积木不能相交,但可沿其表面接触;
- 每块积木的八个顶点坐标必须均为整数(即积木必须与坐标轴对齐),且所有顶点的 z 坐标必须为非负数;
- 每块积木的正方形底面必须平行于地面(即平面 z=0);
- 任何未直接接触地面的积木,其下底面必须与另一块积木的上底面在具有正面积的区域上接触(此时依靠微小凸点实现两块积木的稳固连接)。
例如,下图所示即为一个合法结构:

维托里奥希望构建一个包含 n 块紫色积木的结构,其位置分别为:(x1,0,h)、(x2,0,h)、…、(xn,0,h)——这些是各紫色积木下底面中心的坐标;注意,所有这些紫色积木的 y 坐标均为 0,z 坐标均为 h。维托里奥将使用其他颜色的积木来支撑这些紫色积木。他只愿意将支撑积木放置在下底面中心的 y 坐标等于 0 的位置上。问:最少需要多少块额外的积木?
可以证明,总存在一种合法的构造方式。
输入格式
The first line contains two integers n and h (1≤n≤300, 0≤h≤109) — the number of purple bricks and their common z coordinate.
The second line contains n integers x1,x2,…,xn (1≤xi≤109, xi+1<xi+1) — the x coordinates of the purple bricks (centers of the bases), given in increasing order.
第一行包含两个整数 n 和 h(1≤n≤300,0≤h≤109)—— 分别表示紫色砖块的数量及其共同的 z 坐标。
第二行包含 n 个整数 x1,x2,…,xn(1≤xi≤109,且 xi+1<xi+1)—— 表示紫色砖块(底面中心)的 x 坐标,按升序给出。
输出格式
Print the minimum number of additional bricks needed.
输出所需的最少额外砖块数量。
输入输出样例
输入#1
4 0 2 7 11 13
输出#1
0
输入#2
4 1 2 7 11 13
输出#2
3
输入#3
4 100 2 7 11 13
输出#3
107
输入#4
4 3 2 5 8 11
输出#4
8
说明/提示
In the first sample, all the purple bricks lie on the ground, so no additional bricks are needed.
In the second sample, Vittorio will have to place supporting bricks under the purple bricks, and he can use a single brick to support both the third and the fourth purple bricks. For example, he can place additional bricks at positions (3,0,0), (7,0,0) and (12,0,0). It can be shown that it is impossible to build a valid construction using less than 3 additional bricks.
In the fourth sample, a possible structure that minimizes the number of additional bricks is shown in the problem description.
在第一个样例中,所有紫色砖块都位于地面上,因此不需要额外的砖块。
在第二个样例中,维托里奥需要在紫色砖块下方放置支撑砖块,并且他可以使用一块砖同时支撑第三和第四块紫色砖块。例如,他可以在位置 (3,0,0)、(7,0,0) 和 (12,0,0) 处放置额外的砖块。可以证明,无法用少于 3 块额外砖块构建出合法的结构。
在第四个样例中,问题描述中展示了一种使额外砖块数量最小化的可能结构。
输入解题思路,AI测评打分。不知道怎么写?