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

Last updated at Posted at 2019-04-16

AtCoder ABC 037 A&B&C

AtCoder - 037

2019/05/27
 問題名修正
 B問題のコードの書き方を修正 int[][]の生成部分

A - 饅頭

  • 安いほうをたくさん買う
	private void solveA() {
		int a = nextInt();
		int b = nextInt();
		int c = nextInt();

		int num = Integer.min(a, b);

		out.println(c / num);
	}

B - 編集

  • 指定された範囲を指定された値で書き換える
  • 重複操作になる箇所を省けたら早いんだろうけど、、、
	private void solveB() {
		int numN = nextInt();
		int numQ = nextInt();

		int[][] wk = Stream.generate(() -> new int[] { nextInt(), nextInt(), nextInt() }).limit(numQ)
				.toArray(int[][]::new);
		//		int[][] wk = IntStream.range(0, numQ).collect(() -> new int[numQ][3],
		//				(t, i) -> {
		//					t[i][0] = nextInt();
		//					t[i][1] = nextInt();
		//					t[i][2] = nextInt();
		//				}, (t, u) -> {
		//					Stream.concat(Arrays.stream(t), Arrays.stream(u));
		//				});

		int[] res = new int[numN];
		for (int j = 0; j < wk.length; j++) {
			Arrays.fill(res, wk[j][0] - 1, wk[j][1], wk[j][2]);
		}

		Arrays.stream(res).forEach(i -> out.println(i));
	}

C - 総和

  • 最初にlength分の数値を足す

  • その後は、後ろにずらすたびに、範囲外になった値を消して範囲内になった値を足す

  • 最後は回収

  • 回収のところ、本体の累積を出すところにマージできるな。。。

	private void solveC() {
		int numN = nextInt();
		int numK = nextInt();
		long[] wk = LongStream.range(0, numN).map(i -> nextLong()).toArray();

		int length = numN - numK + 1;

		long[] res = new long[numN];

		res[0] = wk[0];

		for (int i = 1; i < numN; i++) {
			if (i < length) {
				res[i] += wk[i] + res[i - 1];
			} else {
				res[i] += wk[i] + res[i - 1] - wk[i - length];

			}
		}
		long resNum = 0;
		for (int i = length - 1; i < res.length; i++) {
			resNum += res[i];
		}

		out.println(resNum);
	}
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?