CF243D.Cubes

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

One day Petya got a set of wooden cubes as a present from his mom. Petya immediately built a whole city from these cubes.

The base of the city is an n × n square, divided into unit squares. The square's sides are parallel to the coordinate axes, the square's opposite corners have coordinates (0, 0) and (n, n). On each of the unit squares Petya built a tower of wooden cubes. The side of a wooden cube also has a unit length.

After that Petya went an infinitely large distance away from his masterpiece and looked at it in the direction of vector v = (v__x, v__y, 0). Petya wonders, how many distinct cubes are visible from this position. Help him, find this number.

Each cube includes the border. We think that a cube is visible if there is a ray emanating from some point p, belonging to the cube, in the direction of vector  - v, that doesn't contain any points, belonging to other cubes.

一天,佩佳从妈妈那里收到了一套木质立方体作为礼物。佩佳立刻用这些立方体搭建了一座完整的“城市”。

这座城市的底座是一个 n×nn \times n 的正方形,被划分为若干单位正方形。该正方形的边与坐标轴平行,其一对对角顶点的坐标分别为 (0, 0)(0,\,0) 和 (n, n)(n,\,n)。在每个单位正方形上,佩佳都堆叠起一座木质立方体塔。每个木质立方体的边长也为单位长度。

之后,佩佳退到了离他的杰作无穷远的地方,并沿向量 v=(vx, vy, 0)\mathbf{v} = (v_x,\,v_y,\,0) 的方向观察它。佩佳想知道:从这个视角出发,有多少个互不相同的立方体是可见的?请你帮他求出这个数目。

每个立方体均包含其边界。我们认为一个立方体是可见的,当且仅当存在某个属于该立方体的点 pp,使得从 pp 出发、沿向量 −v-\mathbf{v} 方向发出的一条射线,不经过任何其他立方体内的点。

输入格式

The first line contains three integers n, v__x and v__y (1 ≤ n ≤ 103, |v__x|, |v__y| ≤ |104|, |v__x| + |v__y| > 0).

Next n lines contain n integers each: the j-th integer in the i-th line a__ij (0 ≤ a__ij ≤ 109, 1 ≤ i, j ≤ n) represents the height of the cube tower that stands on the unit square with opposite corners at points (i - 1, j - 1) and (i, j).

第一行包含三个整数 nn、vxv_x 和 vyv_y(1 ≤ n ≤ 1031 \leq n \leq 10^3,∣vx∣, ∣vy∣ ≤ 104|v_x|, |v_y| \leq 10^4,∣vx∣ + ∣vy∣ > 0|v_x| + |v_y| > 0)。

接下来的 nn 行,每行包含 nn 个整数:第 ii 行中的第 jj 个整数 aija_{ij}(0 ≤ aij ≤ 1090 \leq a_{ij} \leq 10^9,1 ≤ i, j ≤ n1 \leq i, j \leq n)表示位于以点 (i − 1, j − 1)(i - 1, j - 1) 和 (i, j)(i, j) 为对角顶点的单位正方形上的立方体塔的高度。

输出格式

Print a single integer — the number of visible cubes.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输出一个整数——可见立方体的数量。

请注意,在 C++ 中读取或写入 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。

输入输出样例

  • 输入#1

    5 -1 2
    5 0 0 0 1
    0 0 0 0 2
    0 0 0 1 2
    0 0 0 0 2
    2 2 2 2 3

    输出#1

    20
  • 输入#2

    5 1 -2
    5 0 0 0 1
    0 0 0 0 2
    0 0 0 1 2
    0 0 0 0 2
    2 2 2 2 3

    输出#2

    15

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

首页