TopCoder SRM 296 DIV 1 Easy 練習
問題
CDに入る楽曲のサイズ、楽曲の長さ、楽曲の数が与えられる。
各楽曲を一秒の空白を挟んで録音するとき、必要なCDの枚数を求めなさい。
ただし、CDに入っている楽曲の数が13の倍数に決してならないこと。
解
いろんなケースについて考えられれば大丈夫。
using System; using System.Text; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; public class NewAlbum { public int leastAmountOfCDs(int nSongs, int length, int cdCapacity) { int spc = (cdCapacity+1) / (length+1); if (spc % 13 == 0) spc--; int res = nSongs / spc; int rem = nSongs - spc * res; if (rem == 0) return res; if (res == 0 && rem % 13 == 0) return 2; if (rem + 1 == spc && rem % 13 == 0) return res + 2; return res + 1; } }