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

Posted at

AtCoder ABC 068 A&B&C

AtCoder - 068

A問題

  • 問題文上は0埋めいらないので、本当は"ABC" + numNでもよい
	private void solveA() {
		int numN = nextInt();

		out.println("ABC" + String.format("%03d", numN));
	}

B問題

  • 2で何回割れるのか?
  • 一つ一つチェックするfunction()を作ったけど、、、結局のところ「N以下の2の倍数の最大値」を出せばよい
    • $N\leqq100$ なので、 ${1,2,4,8,16,32,64}$ の中でN以下の最大を探すだけではある。
	private void solveB() {
		int numN = nextInt();

		int res = 0;
		int index = 0;
		for (int i = numN; i > 0; i--) {
			int wk = chkB(i);
			if (res <= wk) {
				res = wk;
				index = i;
			}
		}

		out.println(index);
	}

	private int chkB(int numN) {
		int cnt = 0;
		while (numN > 0) {
			if (numN % 2 == 0) {
				numN /= 2;
				cnt++;
			} else {
				break;
			}
		}
		return cnt;
	}

C問題

  • 島1から始まり、2回で島Nにたどり着けることが条件なので

    • $a_i=1$ の $b_i$ を取得して、
    • $a_i=b_i$ かつ $b_i=N$ となっている組が存在するかを調べればよい
  • 2回で行くという限定条件下でのコード

  1. $a_i=1$ の $b_i$ をsetに詰める(from)
  2. $b_i=N$ の $a_i$ をsetに詰める(to)
  3. fromの要素がtoの要素に含まれるなら2回で行ける
	private void solveC() {
		int numN = nextInt();
		int numM = nextInt();

		int[][] wk = new int[numM][2];
		Set<Integer> fromSet = new HashSet<Integer>();
		Set<Integer> toSet = new HashSet<Integer>();

		for (int i = 0; i < numM; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
			if (wk[i][0] == 1) {
				fromSet.add(wk[i][1]);
			} else if (wk[i][1] == numN) {
				toSet.add(wk[i][0]);
			}
		}
		for (Integer integer : fromSet) {
			if (toSet.contains(integer)) {
				out.println("POSSIBLE");
				return;
			}
		}

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