CF1851A.Escalator Conversations

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

One day, Vlad became curious about who he can have a conversation with on the escalator in the subway. There are a total of nn passengers. The escalator has a total of mm steps, all steps indexed from 11 to mm and ii-th step has height i⋅ki \cdot k.

Vlad's height is HH centimeters. Two people with heights aa and bb can have a conversation on the escalator if they are standing on different steps and the height difference between them is equal to the height difference between the steps.

For example, if two people have heights 170170 and 180180 centimeters, and m=10,k=5m = 10, k = 5, then they can stand on steps numbered 77 and 55, where the height difference between the steps is equal to the height difference between the two people: k⋅2=5⋅2=10=180−170k \cdot 2 = 5 \cdot 2 = 10 = 180 - 170. There are other possible ways.

Given an array hh of size nn, where hih_i represents the height of the ii-th person. Vlad is interested in how many people he can have a conversation with on the escalator individually.

For example, if n=5,m=3,k=3,H=11n = 5, m = 3, k = 3, H = 11, and h=[5,4,14,18,2]h = [5, 4, 14, 18, 2], Vlad can have a conversation with the person with height 55 (Vlad will stand on step 11, and the other person will stand on step 33) and with the person with height 1414 (for example, Vlad can stand on step 33, and the other person will stand on step 22). Vlad cannot have a conversation with the person with height 22 because even if they stand on the extreme steps of the escalator, the height difference between them will be 66, while their height difference is 99. Vlad cannot have a conversation with the rest of the people on the escalator, so the answer for this example is 22.

一天,弗拉德开始好奇:在地铁的自动扶梯上,他能和哪些乘客进行交谈。一共有 nn 名乘客。自动扶梯共有 mm 级台阶,所有台阶编号从 11 到 mm,其中第 ii 级台阶的高度为 i⋅ki \cdot k。

弗拉德的身高为 HH 厘米。两名身高分别为 aa 和 bb 的人,若站在不同的台阶上,且两人之间的身高差恰好等于他们所站台阶之间的高度差,则他们可以在自动扶梯上交谈。

例如,若两人的身高分别为 170170 和 180180 厘米,且 m=10,k=5m = 10, k = 5,则他们可分别站在编号为 77 和 55 的台阶上——此时台阶间的高度差为 k⋅2=5⋅2=10k \cdot 2 = 5 \cdot 2 = 10,恰好等于两人的身高差 180−170=10180 - 170 = 10。还有其他可行的组合方式。

给定一个长度为 nn 的数组 hh,其中 hih_i 表示第 ii 位乘客的身高。弗拉德想知道:他单独地能与多少名乘客在自动扶梯上交谈。

例如,若 n=5,m=3,k=3,H=11n = 5, m = 3, k = 3, H = 11,且 h=[5,4,14,18,2]h = [5, 4, 14, 18, 2],则弗拉德可以与身高为 55 的乘客交谈(弗拉德站在第 11 级台阶,对方站在第 33 级台阶),也可以与身高为 1414 的乘客交谈(例如弗拉德站在第 33 级台阶,对方站在第 22 级台阶)。弗拉德无法与身高为 22 的乘客交谈,因为即使两人站在扶梯两端的台阶(即第 11 级与第 33 级),其高度差最多为 66,而两人的身高差为 99。弗拉德也无法与其他乘客交谈,因此该例的答案为 22。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

Then the descriptions of the test cases follow.

The first line of each test case contains integers: n,m,k,Hn, m, k, H (1≤n,m≤501 \le n,m \le 50, 1≤k,H≤1061 \le k,H \le 10^6). Here, nn is the number of people, mm is the number of steps, kk is the height difference between neighboring steps, and HH is Vlad's height.

The second line contains nn integers: h1,h2,…,hnh_1, h_2, \ldots, h_n (1≤hi≤1061 \le h_i \le 10^6). Here, hih_i represents the height of the ii-th person.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 测试用例的数量。

随后是各测试用例的描述。

每个测试用例的第一行包含四个整数:n,m,k,Hn, m, k, H(1≤n,m≤501 \le n,m \le 50,1≤k,H≤1061 \le k,H \le 10^6)。其中,nn 表示人数,mm 表示台阶数,kk 表示相邻台阶之间的高度差,HH 表示 Vlad 的身高。

第二行包含 nn 个整数:h1,h2,…,hnh_1, h_2, \ldots, h_n(1≤hi≤1061 \le h_i \le 10^6)。其中,hih_i 表示第 ii 个人的身高。

输出格式

For each test case, output a single integer — the number of people Vlad can have a conversation with on the escalator individually.

对于每个测试用例,输出一个整数——即弗拉德在自动扶梯上可以单独交谈的人数。

输入输出样例

  • 输入#1

    7
    5 3 3 11
    5 4 14 18 2
    2 9 5 6
    11 9
    10 50 3 11
    43 44 74 98 62 60 99 4 11 73
    4 8 8 49
    68 58 82 73
    7 1 4 66
    18 66 39 83 48 99 79
    9 1 1 13
    26 23 84 6 60 87 40 41 25
    6 13 3 28
    30 70 85 13 1 55

    输出#1

    2
    1
    4
    1
    0
    0
    3

说明/提示

The first example is explained in the problem statement.

In the second example, Vlad can have a conversation with the person with height 1111.

In the third example, Vlad can have a conversation with people with heights: 44,74,98,6244, 74, 98, 62. Therefore, the answer is 44.

In the fourth example, Vlad can have a conversation with the person with height 7373.

第一个示例在题目描述中已作解释。

在第二个示例中,Vlad 可以与身高为 1111 的人交谈。

在第三个示例中,Vlad 可以与身高分别为 44,74,98,6244, 74, 98, 62 的人交谈。因此,答案为 44。

在第四个示例中,Vlad 可以与身高为 7373 的人交谈。

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

首页