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 - 047- A&B&C

Last updated at Posted at 2019-04-04

AtCoder ABC 047 A&B&C

AtCoder - 047

2019/05/27
 問題名修正
 B問題のコードの書き方を修正 int[][]の生成部分

A - キャンディーと2人の子供 / Fighting over Candies

  • {$A=B,B=C,C=A$}が成り立つかを判定
	private void solveA() {
		int numA = nextInt();
		int numB = nextInt();
		int numC = nextInt();

		if (numA + numB == numC || numB + numC == numA || numA + numC == numB) {
			out.println("Yes");
		} else {
			out.println("No");
		}
	}

B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)

コードが無駄に長いが、、、

  • 白いエリアのサイズは最初 $左下=(0,0),右下=(x,y)$ 
  • 条件にしたがって、左下と右下の値を変化させていく
	private void solveB() {
		int numW = nextInt();
		int numH = nextInt();
		int numN = nextInt();

		int[][] wk = Stream.generate(() -> new int[] { nextInt(), nextInt(), nextInt() }).limit(numN)
				.toArray(int[][]::new);
		//		int[][] wk = IntStream.range(0, numN).collect(() -> new int[numN][3],
		//				(t, i) -> {
		//					t[i][0] = nextInt();
		//					t[i][1] = nextInt();
		//					t[i][2] = nextInt();
		//				},
		//				(t, u) -> {
		//					Stream.concat(Arrays.stream(t), Arrays.stream(u));
		//				});

		final int[][] area = new int[][] { { 0, 0 }, { numW, numH } };

		for (int[] js : wk) {
			switch (js[2]) {
			case 1:
				if (area[0][0] < js[0]) {
					area[0][0] = js[0];
				}
				break;
			case 2:
				if (area[1][0] > js[0]) {
					area[1][0] = js[0];
				}
				break;
			case 3:
				if (area[0][1] < js[1]) {
					area[0][1] = js[1];
				}
				break;
			case 4:
				if (area[1][1] > js[1]) {
					area[1][1] = js[1];
				}
				break;

			default:
				break;
			}

		}

		/*
		 * 計算していった結果、(起点x,起点y),(終点x,終点y)の位置が逆転しているときがある
		 * 入力値例:
		 * 5 4 2
		 * 3 1 1
		 * 2 1 3
		 */
		int x = area[1][0] - area[0][0] > 0 ? area[1][0] - area[0][0] : 0;
		int y = area[1][1] - area[0][1] > 0 ? area[1][1] - area[0][1] : 0;
		int res = x * y;
		out.println(res);
	}

C - 一次元リバーシ / 1D Reversi

動きは以下の様になる。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
start W B W B W B W B
1 W B W B W B W W W
2 W B W B W B B B B B
3 W B W B W W W W W W W
4 W B W B B B B B B B B B
5 W B W W W W W W W W W W W
6 W B B B B B B B B B B B B B
7 W W W W W W W W W W W W W W W
  • WとBが変る場所を数えればよい
	private void solveC() {
		char[] board = next().toCharArray();

		long count = 0;
		/*
		 * WとBのギャップ区間のみ数えればよい
		 */
		for (int i = 1; i < board.length; i++) {
			if (board[i] != board[i - 1]) {
				count++;
			}
		}

		out.println(count);
	}
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?