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

Posted at

AtCoder ABC 083 A&B&C

AtCoder - 083

A問題

  • 比較
	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;
		int numC = 0;
		int numD = 0;

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

			if (numA + numB == numC + numD) {
				System.out.println("Balanced");
			} else if (numA + numB > numC + numD) {
				System.out.println("Left");
			} else if (numA + numB < numC + numD) {
				System.out.println("Right");
			}

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

B問題

  • ただ単純に、1-Nまで各桁の和を調べ、 $A \geqq 各桁の和 \geqq B$となる数値を出力
    • 12 -> 1+2=3
  • 各桁の和は $mod10$ , $divide 10$を繰り返せばよい(modの値を+していく)
    • $12 \quad \rightarrow \quad mod 10 = 2 \quad \rightarrow \quad 12/10 = 1 \quad \rightarrow \quad mod10=1$
private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numA = 0;
		int numB = 0;

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

			int res = 0;
			for (int i = 1; i <= numN; i++) {

				int wk = 0;
				int tmp = i;
				while (tmp != 0) {
					wk += tmp % 10;
					tmp /= 10;
				}
				if (numA <= wk && wk <= numB) {
					res += i;
				}

			}

			System.out.println(res);

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

C問題

 - $A_{i+1}はA_iの倍数$ということは、$A_1はA_0の倍数$
- $A_0はXの倍数 \rightarrow A_0 = X$
- $A_{i+1}はA_iの倍数 \rightarrow A_{i+1}はXの倍数$
- 数列の長さの最大値なので、倍数が最小であれば良い → 倍数は2が最小(1だと条件を満たさない)
- $X*2n \leqq Y$ 以下になる $nの最大値$ を求める

	private void solveC() {
		Scanner scanner = null;
		long numX = 0;
		long numY = 0;

		try {
			scanner = new Scanner(System.in);
			numX = scanner.nextLong();
			numY = scanner.nextLong();

			long x = numX;
			int res = 0;
			while (x <= numY) {
				x *= 2;
				res++;
			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
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?