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.

ABC - 096- A&B&C

Posted at

AtCoder ABC 096 A&B&C

AtCoder - 096

A問題

  • 高橋は1月に1回発生する
	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();

			//5月だったら4か月は高橋がある・・・1/1 2/2 3/3 4/4
			int res = numA - 1;
			//5月だったら、5日以上であれば高橋
			res += numB >= numA ? 1 : 0;

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

B問題

  • 黒板に書かれている整数の内、一番大きいものを操作するのが一番大きい数字を得られる
  • ソートして一番最後を取りだす
	private void solveB() {
		Scanner scanner = null;
		int[] wk = new int[3];
		int numK = 0;

		try {
			scanner = new Scanner(System.in);
			wk[0] = scanner.nextInt();
			wk[1] = scanner.nextInt();
			wk[2] = scanner.nextInt();
			numK = scanner.nextInt();

			Arrays.sort(wk);

			int res = wk[wk.length - 1];
			for (int i = 0; i < numK; i++) {
				res *= 2;
			}
			wk[wk.length - 1] = res;
			res = 0;
			for (int i = 0; i < 3; i++) {
				res += wk[i];
			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

C問題

  • この問題のポイントは以下
    • 同時に二か所塗ることが必須条件であり、同時に二か所濡れない場合はNGである
	private void solveC() {
		Scanner scanner = null;
		int numH = 0;
		int numW = 0;

		try {
			scanner = new Scanner(System.in);
			numH = scanner.nextInt();
			numW = scanner.nextInt();
			char[][] wk = new char[numH][numW];

			for (int i = 0; i < numH; i++) {
				wk[i] = scanner.next().toCharArray();
			}

			boolean isRepaint = true;
			outside: for (int i = 0; i < numH; i++) {
				for (int j = 0; j < numW; j++) {
					/*
					 * 塗るべき個所を判定
					 */
					if (wk[i][j] == '#') {
						/*
						 * 塗れたかどうか?
						 */
						isRepaint = hasNeighbor(wk, i, j, numH, numW);
						if (!isRepaint) {
							break outside;
						}
					}
				}
			}

			System.out.println(isRepaint ? "Yes" : "No");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}


	/*
	 * 上下左右に隣接する黒色で塗る予定のマスがあるか判定
	 * 1つ以上あれば二つ塗れる
	 */
	private boolean hasNeighbor(char[][] wk, int i, int j, int maxH, int muxW) {
		int cnt = 0;

		if (i > 0 && wk[i - 1][j] == '#') {
			cnt++;
		}
		if (j < muxW - 1 && wk[i][j + 1] == '#') {
			cnt++;
		}
		if (i < maxH - 1 && wk[i + 1][j] == '#') {
			cnt++;
		}
		if (j > 0 && wk[i][j - 1] == '#') {
			cnt++;
		}

		return cnt > 0;
	}
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?