SRM478 DIV2 250 KiwiJuiceEasy
問題文のとおりにシミュレーション。
1 <= capacities[i],bottles[i] <= 1,000,000
で要素数が最大50だからインクリメント・デクリメントを繰り返しても余裕で間に合う。
#include <vector> using namespace std; class KiwiJuiceEasy { public: vector <int> thePouring(vector <int> capacities, vector <int> bottles, vector <int> fromId, vector <int> toId) { for(int k=0;k<fromId.size();++k) { int i=fromId[k]; int j=toId[k]; while (bottles[j]<capacities[j] && bottles[i]>0) { bottles[j]++; bottles[i]--; } } return bottles; } };
チーター本の間違ってる気がするところ その4
細かいとこだけど p.94 Fig.5-14 Step4
「追加した文字数の2を返す」ってあるけど返すのは
回文にした後の文字列全体の長さなので 2+6=8 なのではないだろうか。
チーター本の間違ってる気がするところ その3
p.83 Table 5-2 9,10の3進表記が間違ってる。正しくは以下のようになるはず。
10進表記 | 変形式 | 3進表記 | 各桁の和 |
9 | 1x3^2 + 0x3^1 + 0x3^0 | 100 | 1 |
10 | 1x3^2 + 0x3^1 + 1x3^0 | 101 | 2 |
チーター本の間違ってる気がするところ その2
p.78 最後の文 「ソートを利用すると、ソースコードは〜」とあるけどソートしてない。
ソートを利用すると例えば以下のようなものになるんじゃないだろうか。
#include <algorithm> #include <vector> using namespace std; class Cryptography { public: long long encrypt(vector <int> numbers) { sort(numbers.begin(), numbers.end()); numbers[0]++; long long res=1; for(int i=0;i<numbers.size();++i) res*=numbers[i]; return res; } };
チーター本の間違ってる気がするところ
p.67 2行目
「最小値を返す」ってあるけど「最大値を返す」だよね。