A. Escalator Conversations

题目:

 样例:

输入
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;
}

最后提交:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值