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

Posted at

AtCoder ABC 087 A&B&C

AtCoder - 087

A問題

	private void solveA() {
		Scanner scanner = null;
		int numX = 0;
		int numA = 0;
		int numB = 0;

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

			System.out.println((numX - numA) % numB);

			System.out.println("");

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

B問題

  • ただ単にforでカウントした。Bだと時間を気にしていないのでこれでもTLEにはならない。。。
	private void solveB() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;
		int numC = 0;
		int numX = 0;

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

			int res = 0;
			for (int i = 0; i <= numA; i++) {
				for (int j = 0; j <= numB; j++) {
					for (int k = 0; k <= numC; k++) {
						if (i * 500 + j * 100 + k * 50 == numX) {
							res++;
						}
					}
				}
			}

			System.out.println(res);

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

C問題

  • 右を選択した場合と下を選択した場合のどちらが飴を多くとれるか、再帰で調べる
	private void solveC() {
		Scanner scanner = null;
		int numN = 0;

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

			int[][] wk = new int[2][numN];

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

			System.out.println(getAme(wk, 0, 0));

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

	private int getAme(int[][] wk, int x, int y) {
		int res = 0;

		if (x >= 2 || y >= wk[0].length) {
			return 0;
		}

		int val1 = getAme(wk, x + 1, y) + wk[x][y];
		int val2 = getAme(wk, x, y + 1) + wk[x][y];

		res = Math.max(val1, val2);
		return res;
	}
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?