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

Posted at

AtCoder ABC 103 A&B&C

AtCoder - 103

A問題

  • 配列に格納してソート
  • ソートした順に作業
	private void solveA() {
		Scanner scanner = null;

		try {
			scanner = new Scanner(System.in);
			int[] wk = new int[3];

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

			Arrays.sort(wk);
			int res = Math.abs(wk[0] - wk[1]) + Math.abs(wk[1] - wk[2]);

			System.out.println(res);

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

B問題

  • kyotoという文字列の最後の文字を最初に持っていって循環させる

    • kyoto
      • okyot
        • tokyo
          • .....
  • 一文字ずつ判定しても何とかなるけど、、、

    • 文字列Tは文字列Sの長さを超えることはないので、 kyoto+kyoto=kyotokyoto としてしまって kyotokyoto のなかに文字列Tが含まれるのかを判定するのが早い
	private void solveB() {
		Scanner scanner = null;
		String s;
		String t;

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

			s = s + s;

			System.out.println(s.contains(t) ? "Yes" : "No");

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

C問題

$f(m) ; =; (m ; mod ; a_1) ; + ; (m ; mod ; a_2) ; +...+ ; (m ; mod ; a_N)$

  • $f(m)$ を最大化したい

    • 細かく見ると
      • $(m ; mod ; a_i) $ の最小は $(m ; mod ; a_i) =0$
      • $(m ; mod ; a_i) $ の最大は $(m ; mod ; a_i) =a_i-1$ <- $a_i$の余りなので
    • $f(m)$ を最大化するには、 $(m ; mod ; a_i) $ が最大化できればよい
  • $m = a_1 × a_2 × · · · × a_N$ とすると、各 i について $(m ; mod ; a_i = 0)$ なので、$((m − 1) ; mod ; a_i = a_i − 1)$

    • $(N*A ; mod ; A)$ は $N$ によらず $0$ ...
  • $f(m − 1) = (a_1 − 1) + (a_2 − 1) + ...... + (a_n − 1)$ となり、各項が最大値を取っている


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

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

			int res = 0;
			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextInt();
				res += wk[i] - 1;
			}

			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?