LoginSignup
0
0

More than 3 years have passed since last update.

ABC - 015 - A&B&C

Last updated at Posted at 2019-05-23

AtCoder ABC 015 A&B&C

AtCoder - 015

A - 高橋くんの研修

  • 変数名って会社毎に独特のルールあるよね
    private void solveA() {
        String a = next();
        String b = next();

        out.println(a.length() > b.length() ? a : b);
    }

B - 高橋くんの集計

  • 0ではない数を数えて母数とする
  • 少数は切り上げ
    private void solveB() {
        int n = nextInt();
        double base = 0;
        double total = 0;
        for (int i = 0; i < n; i++) {
            int wk = nextInt();
            if (wk != 0) {
                base++;
                total += wk;
            }
        }

        out.println((int) Math.ceil(total / base));
    }

C - 高橋くんのバグ探し

  • 結構典型的なDFSでした
private void solveC() {
        int n = nextInt();
        int k = nextInt();

        int[][] wk = IntStream.range(0, n).collect(() -> new int[n][k],
                (t, i) -> {
                    for (int j = 0; j < k; j++) {
                        t[i][j] = nextInt();
                    }
                },
                (t, u) -> {
                    Stream.concat(Arrays.stream(t), Arrays.stream(u));
                });

        out.println(recursiveC(wk, 0, 0) ? "Found" : "Nothing");
    }

    private boolean recursiveC(int[][] wk, int currentI, int currenXor) {

        /*
         * 最後の質問までいったので、今までのXORの結果を確認する
         */
        if (currentI >= wk.length) {
            return currenXor == 0;
        }
        boolean res = false;
        /*
         * currentI番目の質問のi番目の選択を選んだ場合のXORを確認していく
         */
        for (int i = 0; i < wk[currentI].length; i++) {
            res = res || recursiveC(wk, currentI + 1, currenXor ^ wk[currentI][i]);
        }

        return res;
    }
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