题目:

样例:
| 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 |
| 2 1 4 1 0 0 3 |
解释:
思路:
这里其实直接模拟即可。
就是题意有点难理解,还得需要多练练,题目的意思就是 找出有多少个人和小弗高度差在步数可以走动的台阶高度之内的
即 abs(h - peoh[i]) < k * m ,又因为我们 高度差是符合 我们走动的步数之间的,
即 abs(h - peoh[i]) % k == 0 就可以了
代码如下:
#include <iostream>
using namespace std;
const int N = 1e7 + 10;
inline void solve()
{
int n,m,k,h,ans = 0;
cin >> n >> m >> k >> h;
int step_height = k * m;
int height_difference[N];
for(int i = 0,height = 0;i < n;++i)
{
cin >> height;
height_difference[i] = abs(h - height);
}
for(int i = 0,height = 0;i < n;++i)
{
if(height_difference[i] % k == 0 && height_difference[i])
{
if(height_difference[i] < step_height) ans++;
}
}
cout << ans << endl;
}
int main()
{
int _t = 1;
cin >> _t;
while(_t--)
{
solve();
}
return 0;
}
最后提交:
![]()

博客围绕一道算法题展开,题目需找出与小弗高度差在步数可走动台阶高度之内的人数。解题思路是直接模拟,满足高度差小于步数乘台阶高度,且高度差能被步数整除,最后给出代码并提及提交。

被折叠的 条评论
为什么被折叠?



