2009-09-27
SoldierLabeling
SRM 446, Div2, Div2 Level-1, Math, 80% |
lowerBound から upperBound の間の桁数の数がラベルされている軍人だけを数えるき、数えるであろう兵隊の数を返せ。
この問題は以前にも解いた問題で、その時は187.99点だった。今回はというと、少し手間取ったが、前回よりは高い点を獲得できた。
200.03/250
class SoldierLabeling { public: int count(int n, int lowerBound, int upperBound) { int count = n; int lower = (int)pow(10.0, lowerBound-1) - 1; int upper = (int)pow(10.0, upperBound) - 1; count -= lower; if (count < 0) return 0; if (upper <= n) count -= n - upper; return count; } };
コメントを書く
トラックバック - http://topcoder.g.hatena.ne.jp/caligue/20090927
リンク元
- 16 http://topcoder.g.hatena.ne.jp/
- 7 http://topcoder.g.hatena.ne.jp/diarylist
- 5 https://www.google.co.jp
- 1 http://topcoder.g.hatena.ne.jp/n4_t/20090927
- 1 http://topcoder.g.hatena.ne.jp/n4_t/20081204/1249827311
- 1 http://www.google.com.bd/search?q=BridgeCrossing+topcoder&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
- 1 http://topcoder.g.hatena.ne.jp/n4_t/19700111
- 1 http://www.google.com/search?hl=en&client=safari&rls=en-us&q=thecardshufflingdivtwo&aq=f&oq=&aqi=
- 1 http://topcoder.g.hatena.ne.jp/cafelier/edit
- 1 http://www.google.com/search?q=approximatePi(int+numSides)&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a