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

Last updated at Posted at 2019-04-23

AtCoder ABC 036 A&B&C

AtCoder - 036

2019/05/27
 問題名修正

A - お茶

  • $b \div a$だけだと端数切捨てなので、 $ b % a$が0より大きければ追加で箱を一つ買う
	private void solveA() {
		int a = nextInt();
		int b = nextInt();

		out.println((b / a) + (b % a > 0 ? 1 : 0));
	}

B - 回転

  • 90度回転
	private void solveB() {
		int numN = nextInt();
		char[][] wk = IntStream.range(0, numN).collect(() -> new char[numN][numN],
				(t, i) -> {
					t[i] = next().toCharArray();
				}, (t, u) -> {
					Stream.concat(Arrays.stream(t), Arrays.stream(u));
				});

		for (int j = 0; j < numN; j++) {
			StringBuilder builder = new StringBuilder();
			for (int k = numN - 1; k >= 0; k--) {
				builder.append(wk[k][j]);
			}
			out.println(builder.toString());
		}
	}

C - 座圧

  • 手法としては座標圧縮というらしい

圧縮結果としては以下のようになる(大小関係のみ保持している感じ)

3 3 1 6 1 -> 1 1 0 2 0
3 3 1 90 1 -> 1 1 0 2 0
9 9 1 10 1 -> 1 1 0 2 0
9 9 5 10 5 -> 1 1 0 2 0
  • 1,3,6をソートする。
3 3 1 6 1 -> 1 1 3 3 6
  • 1は1番目に出現
  • 3は2番目に出現
  • 6は3番目に出現

最小なので、1番目に出現を0番目に置き換えて、$a_i$が出現した番号を出力

3 3 1 6 1 -> 1 1 0 2 0
	private void solveC() {
		int numN = nextInt();
		int[] wk = new int[numN];
		Set<Integer> wkL = new HashSet<Integer>();
		for (int i = 0; i < wk.length; i++) {
			wk[i] = nextInt();
			wkL.add(wk[i]);
		}

		List<Integer> tmp = new ArrayList<Integer>();
		tmp.addAll(wkL);
		Collections.sort(tmp);

		for (int i = 0; i < wk.length; i++) {
			int position = Collections.binarySearch(tmp, wk[i]);
			position = position >= 0 ? position : ~position;
			out.println(position);
		}
	}
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?