LoginSignup
0
0

More than 3 years have passed since last update.

ABC - 132- A&B&C

Last updated at Posted at 2019-07-14

AtCoder ABC 132 A&B&C

AtCoder - 132

Dのcombinationのバグが取れないのでD以降は後回し。

A - Fifty-Fifty

  • 文字をカウントしたら必ず二つないといけない
    private void solveA() {
        String[] a = next().split("");

        Map<String, Long> memo = Arrays.stream(a).collect(Collectors.groupingBy(s -> s, Collectors.counting()));

        for (long elm : memo.values()) {
            if (elm != 2) {
                out.println("No");
                return;
            }
        }
        out.println("Yes");
    }

B - Ordinary Number

  • $p_{i−1}, p_i, p_{i+1}$ の 3 つの数の中で、$p_i$ が 2 番目に小さい
    • 上記を満たせばよいので、$p_{i−1}< p_i< p_{i+1}$ または $p_{i+1} < p_i< p_{i−1}$ を確認する。
    private void solveB() {
        int n = nextInt();
        int[] p = IntStream.range(0, n).map(i -> nextInt()).toArray();

        int res = 0;
        for (int i = 0; i < p.length - 2; i++) {
            if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) || (p[i + 2] < p[i + 1] && p[i + 1] < p[i])) {
                res++;
            }
        }

        out.println(res);
    }

C - Divide the Problems

  • ソートして
  • ARC用とABC用の問題の境目の数を抜き出す
  • 境目の数の差が選択可能な数
    private void solveC() {
        int n = nextInt();
        int[] d = IntStream.range(0, n).map(i -> nextInt()).sorted().toArray();

        out.println(d[n / 2] - d[n / 2 - 1]);
    }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0