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

Last updated at Posted at 2019-04-09

AtCoder ABC 100 A&B&C

AtCoder - 100

A問題

  • 隣り合うケーキを食べてはいけないという制約上、一人が半分以上ケーキを食べることは出来ない
	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

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

			if (numA > 16 / 2 || numB > 16 / 2) {
				System.out.println(":(");
				return;
			}

			System.out.println("Yay!");

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

B問題:ずる解法っぽい・・・

  • ポイントは100で割り切れる

    • そのため、N=100の時に特殊処理が必要
    • $ ・・・98, 99 , 100 , 101 , 102・・・ $ とあった場合
      • $mod \quad 100$ => $ ・・・98, 99 , 0 , 1 , 2・・・ $ となる
      •  たとえば、入力値が 「0 100」 だった場合、結果は 「101」 である
  • D=0 : 100でちょうど0回割り切れる=100で割り切れない。

    • 100は割り切れてしまうのに注意
    • そのため、$1,2,3,4,5 - 99, 101,102$が答えを求める際の数列になる
  • D=1 : 100でちょうど1回割り切れる=100の倍数。

    • たとえば、入力値が $1 100$ だった場合
      • 対象の数値は右のように思えるが $100,200,300,400,500 - 9900, 10000, 10100,10200$
      • 実際のところは$10000$は除外となる $1,2,3,4,5 - 99, 1(100*100で2回割れてしまう), 101,102$
  • D=2 : D=0/1と同様のことが言える

	private void solveB() {
		Scanner scanner = null;
		int numD = 0;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numD = scanner.nextInt();
			numN = scanner.nextInt();
			if (numN == 100) {
				numN++;
			}
			switch (numD) {
			case 0:
				System.out.println(numN);
				break;
			case 1:
				System.out.println(numN * 100);
				break;
			case 2:
				System.out.println(numN * 10000);
				break;
			default:
				break;
			}

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

B問題:問題通りにとくとこっちかな?

  • こっちだと100は割り切れる。。。とか考えなくてよい
  • 普通に1-Nまで100で割る回数を数えていく
	private void solveB2() {
		Scanner scanner = null;
		int numD = 0;
		int numN = 0;

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

			int count = 0;
			int val = 0;

			while (count != numN) {
				val++;
				if (getFunc(val) == numD) {
					count++;
				}
			}
			System.out.println(val);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
	
	private int getFunc(int x) {
		int res = 0;
		while (x % 100 == 0) {
			x = x / 100;
			res++;
		}
		return res;
	}

C問題

  • 偶数の特性と奇数の特性の話
  • 偶数を奇数倍しても2で割れる数が増えるわけではない。。。
	/**
	 * a[i]の操作終了条件は「2で割れなくなったとき」
	 * a[i]を3倍しても「2で割る事の出来る回数は増えない」
	 * そのため、a[i]を2で割れる回数の総計が操作可能回数。
	 */
	private void solveC() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			long[] wk = new long[numN];

			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextLong();
			}

			System.out.println(dpSolveC(wk));

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

	private long dpSolveC(long[] wk) {
		int cnt = 0;
		for (int i = 0; i < wk.length; i++) {
			long wkNum = wk[i];
			while (wkNum % 2 == 0) {
				wkNum /= 2;
				cnt++;
			}
		}
		return cnt;

	}
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?