# A. Escalator Conversations(電扶梯對話) ## 題目連結: [Codeforces](https://codeforces.com/contest/1851/problem/A) ## 解題想法 * 輪流比較每個人 * 如果兩人高度一樣,無法交談 * 如果兩人身高差大於電扶梯最大高度,無法交談 * 如果兩人身高差的倍數不是每個階梯差的高度,無法交談 * 其他狀況則可交談 ## 程式碼 ```py= times = int(input()) #重複做times次 for a in range(times): ppl,steps,steps_h,height = map(int,input().split()) data = [int(i) for i in input().split()] count = 0 for i in data: if i == height: #兩人身高一樣 continue elif abs((i-height)) > steps_h*(steps-1): #兩人身高差大於電扶梯最高差 continue elif (i-height) % steps_h != 0: #兩人身高差不是階梯差的倍數 continue else: count += 1 print(count) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up