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

Posted at

AtCoder ABC 048 A&B&C

AtCoder - 048

A問題

  • それぞれの文字の頭を連結
	private void solveA() {
		String res = next().substring(0, 1) + next().substring(0, 1) + next().substring(0, 1);

		out.println(res);
	}

B問題

  • {$Bで該当する値 - (A-1)で該当する値$} で求める
  • {$a=0$}の時、0も対象に入れるので注意
	private void solveB() {
		long numA = nextLong();
		long numB = nextLong();
		long numX = nextLong();

		//		long max1 = numB % numX;
		//		long res1 = (numB - max1) / numX;
		long res1 = numB / numX;

		if (numA == 0) {
			out.println(res1 + 1);
		} else {
			//			long max2 = (numA - 1) % numX;
			//			long res2 = ((numA - 1) - max2) / numX;
			long res2 = (numA - 1) / numX;
			out.println(res1 - res2);
		}

	}

C問題

  • とりあえず、$a_0$を基準とする(基準値決めないと何も出来ない)
  1. $a_0 + a_1 \leqq x $ とするために必要な数値が操作回数
    • 操作した結果を$a_1$に反映
    • $a_1$で吸収しきれない($a_1 < 0$となる)のであれば、溢れた分を$a_0$に転嫁
  2. 1を$a_N$まで順に繰り返せば均される
	private void solveC() {
		int numN = nextInt();
		long numX = nextInt();
		long[] wk = new long[numN];
		long cnt = 0;
		for (int i = 0; i < numN; i++) {
			wk[i] = nextInt();
			if (i != 0) {
				if (wk[i] + wk[i - 1] > numX) {
					long diff = (wk[i] + wk[i - 1]) - numX;
					/*
					 * diffをwk[i]から引いたらマイナスの可能性がある
					 * numX=100
					 * wk[i]=10,wk[i-1]=99
					 */
					if (diff <= wk[i]) {
						wk[i] = wk[i] - diff;
					} else {
						/*
						 * wk[i]は0
						 * wk[i+1]に差分を転嫁する事は出来ないが、wk[i-1]に転嫁することはできる
						 * wk[i-1]に転嫁してもwk[i-2]+wk[i-1]がXを上回ることはないため
						 */
						wk[i] = 0;
						wk[i - 1] = wk[i - 1] - (diff - wk[i]);
					}
					cnt += diff;
				}
			}
		}

		out.println(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?