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

Posted at

AtCoder ABC 088 A&B&C

AtCoder - 088

A問題

  • 無限の500円硬貨なので、$mod \quad 500$のあまりを求める
  • あまりが手持ちの1円硬貨よりも多いか少ないか
	private void solveA() {
		Scanner scanner = null;
		int numN = 0;
		int numA = 0;

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

			int res = numN % 500;

			System.out.println(res <= numA ? "Yes" : "No");

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

B問題

  • 得点を最大化するには得点の大きいカードから交互に取っていけばよい
	private void solveB() {
		Scanner scanner = null;
		int numN = 0;

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

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

			Arrays.sort(wk);

			int alice = 0;
			int bob = 0;
			boolean convert = true;
			for (int i = wk.length - 1; i >= 0; i--) {
				if (convert) {
					alice += wk[i];
				} else {
					bob += wk[i];
				}
				convert = !convert;
			}

			System.out.println(alice - bob);

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

C問題

  • 問題より
    • {$A_1,A_i$}={$A_1,A_3$} Aは3種類の数値
    • {$B_1,B_i$}={$B_1,B_3$} Bは3種類の数値
    • かつ、100以下の数値なので総当りを試す
  • 先ず、{$C_{11}=A_1+B_1$}/{$C_{12}=A_1+B_2$}/{$C_{13}=A_1+B_3$}なので
    • {$A_1=0$}として、{$B_1,B_2,B_3$}を求める
    • {$B_1,B_2,B_3$}から{$A_2,A_3$}を求める
    • {$C_{11} - C_{33}$}まで{$A_i+B_j$}が成り立つならOK。
    • 成り立たないなら{$A_1=1$}として再度やり直し($A_1=0+1$をする)
	private void solveC() {
		Scanner scanner = null;

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

			int[][] wk = new int[3][3];

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

			System.out.println(chkC(wk, max, 0) ? "Yes" : "No");

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

	private boolean chkC(int[][] wk, int max, int currentA) {
		if (currentA > max) {
			return false;
		}

		int[] aA = new int[3];
		int[] bA = new int[3];

		aA[0] = currentA;
		for (int j = 0; j < bA.length; j++) {
			bA[j] = wk[0][j] - currentA;
		}
		for (int i = 0; i < aA.length; i++) {
			aA[i] = wk[i][0] - bA[0];
		}
		boolean isMatch = true;
		outside: for (int i = 0; i < bA.length; i++) {
			for (int j = 0; j < bA.length; j++) {
				isMatch = wk[i][j] == aA[i] + bA[j];
				if (!isMatch) {
					break outside;
				}
			}
		}
		return isMatch ? true : chkC(wk, max, currentA + 1);
	}
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?