A16158 | Escalator Conversations
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
One day, Vlad became curious about who he can have a conversation with on the escalator in the subway. There are a total of $n$ passengers. The escalator has a total of $m$ steps, all steps indexed from $1$ to $m$ and $i$ -th step has height $i \cdot k$ .
Vlad's height is $H$ centimeters. Two people with heights $a$ and $b$ 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 $170$ and $180$ centimeters, and $m = 10, k = 5$ , then they can stand on steps numbered $7$ and $5$ , where the height difference between the steps is equal to the height difference between the two people: $k \cdot 2 = 5 \cdot 2 = 10 = 180 - 170$ . There are other possible ways.
Given an array $h$ of size $n$ , where $h_i$ represents the height of the $i$ -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 = 11$ , and $h = [5, 4, 14, 18, 2]$ , Vlad can have a conversation with the person with height $5$ (Vlad will stand on step $1$ , and the other person will stand on step $3$ ) and with the person with height $14$ (for example, Vlad can stand on step $3$ , and the other person will stand on step $2$ ). Vlad cannot have a conversation with the person with height $2$ because even if they stand on the extreme steps of the escalator, the height difference between them will be $6$ , while their height difference is $9$ . Vlad cannot have a conversation with the rest of the people on the escalator, so the answer for this example is $2$ .
Vlad's height is $H$ centimeters. Two people with heights $a$ and $b$ 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 $170$ and $180$ centimeters, and $m = 10, k = 5$ , then they can stand on steps numbered $7$ and $5$ , where the height difference between the steps is equal to the height difference between the two people: $k \cdot 2 = 5 \cdot 2 = 10 = 180 - 170$ . There are other possible ways.
Given an array $h$ of size $n$ , where $h_i$ represents the height of the $i$ -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 = 11$ , and $h = [5, 4, 14, 18, 2]$ , Vlad can have a conversation with the person with height $5$ (Vlad will stand on step $1$ , and the other person will stand on step $3$ ) and with the person with height $14$ (for example, Vlad can stand on step $3$ , and the other person will stand on step $2$ ). Vlad cannot have a conversation with the person with height $2$ because even if they stand on the extreme steps of the escalator, the height difference between them will be $6$ , while their height difference is $9$ . Vlad cannot have a conversation with the rest of the people on the escalator, so the answer for this example is $2$ .
输入格式
The first line contains a single integer $t$ ( $1 \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, H$ ( $1 \le n,m \le 50$ , $1 \le k,H \le 10^6$ ). Here, $n$ is the number of people, $m$ is the number of steps, $k$ is the height difference between neighboring steps, and $H$ is Vlad's height.
The second line contains $n$ integers: $h_1, h_2, \ldots, h_n$ ( $1 \le h_i \le 10^6$ ). Here, $h_i$ represents the height of the $i$ -th person.
Then the descriptions of the test cases follow.
The first line of each test case contains integers: $n, m, k, H$ ( $1 \le n,m \le 50$ , $1 \le k,H \le 10^6$ ). Here, $n$ is the number of people, $m$ is the number of steps, $k$ is the height difference between neighboring steps, and $H$ is Vlad's height.
The second line contains $n$ integers: $h_1, h_2, \ldots, h_n$ ( $1 \le h_i \le 10^6$ ). Here, $h_i$ represents the height of the $i$ -th person.
输出格式
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 $11$ .
In the third example, Vlad can have a conversation with people with heights: $44, 74, 98, 62$ . Therefore, the answer is $4$ .
In the fourth example, Vlad can have a conversation with the person with height $73$ .
In the second example, Vlad can have a conversation with the person with height $11$ .
In the third example, Vlad can have a conversation with people with heights: $44, 74, 98, 62$ . Therefore, the answer is $4$ .
In the fourth example, Vlad can have a conversation with the person with height $73$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted