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.

SRM150 DIV2 250

Posted at

問題文概略

一日に与えられる仕事とこなせる仕事の量が決まっている。
仕事を終えられる日数を求めよ。

書いたコード

解けなかった。

他の参加者のコードを読んで修正した

public class WidgetRepairs {

	public int days(int[] arrivals, int numPerDay) {

		int n = arrivals.length;
		int w = 0, ans = 0;
		for (int i = 0; i < n; i++){
			w += arrivals[i];
			if(w > 0) {
				ans++;
				w -= Math.min(w, numPerDay);
			}
		}
		if(w > 0) {
			ans += (int) Math.ceil( ((double) w/ numPerDay));
		}
		return ans;
	}
}


雑感

仕事の量も配列にいれて管理しようとコードを書いていたら混乱して解けなかった。
単純に一つ変数を用意して、管理すればよかったのか。

仕事量を計算する時の以下の考えかたは覚えておこう。

w -= Math.min(w, numPerDay);
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?