0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AtCoder ABC 064 A&B&C

Posted at

AtCoder ABC 064 B&C

AtCoder - 064

A問題

  • 入力値を3桁の数に変換して、それが4の倍数かどうかを判定する
	private void solveA() {
		int numR = nextInt();
		int numG = nextInt();
		int numB = nextInt();

		int num = (numR * 100 + numG * 10 + numB);

		out.println(num % 4 == 0 ? "YES" : "NO");
	}

B問題

  • 入力値の最小値と最大値の差分が移動距離となる
  • どーーーしてもStreamを使ってみたかったので書いたけど、こんなのでいいのか???
	private void solveB() {
		int numN = nextInt();
		Map<Integer, Integer> wk = new TreeMap<Integer, Integer>();
		IntStream.range(0, numN).forEach(i -> wk.merge(nextInt(), 1, (oldV, newV) -> oldV + newV));

		AtomicInteger min = new AtomicInteger(Integer.MAX_VALUE);
		AtomicInteger max = new AtomicInteger(0);
		wk.keySet().stream().forEach(key -> {
			min.set(Math.min(min.intValue(), key));
			max.set(Math.max(max.intValue(), key));
		});

		out.println(max.intValue() - min.intValue());
	}

C問題

  • こいつもはまった問題。

  • はまった理由、、、色は最大8色だと思い込んだ。。。質問欄に8色以上あると書いてあったのをちゃんと読めば。。。

  • どのレートに人がいるかを調べればよい

    • 基本は人を数える必要はない(どの色の種類があるかを調べるだけなので絵)
    • レート3200以上の人のみ、何人いるかを数える
  • 色の種類最小

    • 3200未満のレートの人が存在する(色の種類が1以上ある)
      • 3200以上の人たちは、既に存在する色になればよい(カウントしない)
    • 3200未満のレートの人が存在しない(色の種類が1つもない)
      • 3200以上の人たちは、1つの色を新しく作成してその色に集まればよい(1としてカウントする)
  • 色の種類最大

    • 以下の二つの値を足す
      • 3200未満の人たちの色の種類
      • 3200以上の人たちは全員別の色となる
	private void solveC() {
		int numN = nextInt();

		Set<Integer> set = new HashSet<>();
		int cnt = 0;
		for (int i = 0; i < numN; i++) {
			int key = nextInt();
			if (key < 400) {
				set.add(1);
			} else if (key < 800) {
				set.add(2);
			} else if (key < 1200) {
				set.add(3);
			} else if (key < 1600) {
				set.add(4);
			} else if (key < 2000) {
				set.add(5);
			} else if (key < 2400) {
				set.add(6);
			} else if (key < 2800) {
				set.add(7);
			} else if (key < 3200) {
				set.add(8);
			} else {
				cnt++;
			}

		}
		/*
		 * 赤のみなら赤全員が同じ色になればよい
		 * 赤以外がいるのなら、赤以外の合計
		 */
		int min = set.size() == 0 ? 1 : set.size();
		/*
		 * 赤+その他の色の合計がmax
		 * 色の種類数のmaxを求めるのだが、色の種類数のmaxは8ではない
		 * 問題文に「レートが3200以上になると色を自由に変えることが出来ます」
		 * これは、「問題文中の8色の中で自由に変える」ではなく「8色ではない別の色に自由に変える」の意味
		 * なので、以下のコードを追加すると間違える
		 * ->質問のタブに同じことを聞いている人がいた。。。質問蘭を読むの大事
		 *		max = max > 8 ? 8 : max;
		 */
		int max = set.size() + cnt;
		out.println(min + " " + max);
	}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?