Codeforces算法心得——A. Escalator Conversations

大家好,我是晴天学长,今天开始尝试一些外国的题目了,不得不说,创新性挺高的,然后是全英文,也可以练练英文的水平,后面我会持续的更新的!加油!


1 )A. Escalator Conversations

Codeforces算法心得——A. Escalator Conversations_第1张图片

2) .算法思路

自动扶梯对话(直接暴力)
1.接收数据N组
2.接收数据n,m,k,H
3.再接受身高的数组
4.初始变量ans=0;
5.开始遍历数组,相减是倍数的话就ans++,注意不能和自己一样高
6.输出ans


3).代码示例

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Escalator_Conversations {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] s= in.readLine().split(" ");
        int L = Integer.parseInt(s[0]);
        for (int i = 0; i < L; i++) {
            s= in.readLine().split(" +");
            int n = Integer.parseInt(s[0]);
            int m = Integer.parseInt(s[1]);
            int k = Integer.parseInt(s[2]);
            int H = Integer.parseInt(s[3]);
            s = in.readLine().split(" ");
            int[] N = new int[s.length];
            for (int j = 0; j < n; j++) {
                N[j] = Integer.parseInt(s[j]);
            }
            int ans = 0;
            for (int j = 0; j < N.length; j++) {
                if (Math.abs(H - N[j]) % k == 0 && Math.abs(H - N[j]) / k <= m - 1&&H!=N[j]) {
                    ans++;
                } else continue;
            }
            System.out.println(ans);
        }
    }
}

4).总结

  • 英文翻译哈哈哈
  • 细节处理

你可能感兴趣的:(算法,算法,python,开发语言)